diofanto33

python_env_setup.sh

Apr 21st, 2026 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.18 KB | Software | 0 0
  1. #!/bin/bash
  2. set -e
  3.  
  4. echo "==> [1/5] Instalando dependencias del sistema..."
  5. sudo apt update -y
  6. sudo apt install -y python3 python3-venv python3-pip
  7.  
  8. echo "==> [2/5] Creando entorno virtual en /home/visitante/.venv ..."
  9. sudo -u visitante bash -c '
  10.  if [ ! -d /home/visitante/.venv ]; then
  11.    python3 -m venv /home/visitante/.venv
  12.    echo "  Entorno virtual creado."
  13.  else
  14.    echo "  El entorno virtual ya existe, se omite la creación."
  15.  fi
  16. '
  17.  
  18. echo "==> [3/5] Instalando paquetes Python en el venv..."
  19. sudo -u visitante /home/visitante/.venv/bin/pip install --upgrade \
  20.   pip \
  21.   ipykernel \
  22.   notebook \
  23.   numpy \
  24.   matplotlib
  25.  
  26. echo "==> [4/5] Registrando kernel de Jupyter..."
  27. sudo -u visitante /home/visitante/.venv/bin/python -m ipykernel install \
  28.   --user \
  29.   --name visitante-env \
  30.   --display-name "Python 3 (numpy/matplotlib)"
  31.  
  32. echo "==> [5/5] Eliminando kernel python3 duplicado si existe..."
  33. sudo -u visitante bash -c '
  34.  /home/visitante/.venv/bin/jupyter kernelspec uninstall -f python3 2>/dev/null || true
  35. '
  36.  
  37. echo ""
  38. echo "✓ Setup completado. Kernels disponibles para visitante:"
  39. sudo -u visitante /home/visitante/.venv/bin/jupyter kernelspec list
Advertisement
Add Comment
Please, Sign In to add comment