Advertisement
J2897

New Python environment with JupyterLab Kernel

Oct 17th, 2022 (edited)
1,212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.65 KB | None | 0 0
  1. @echo OFF
  2. cls
  3.  
  4. REM Description...
  5. ::
  6. :: This is basically the same as the other version here:
  7. ::
  8. ::      https://pastebin.com/mbcK7zxh
  9. ::
  10. :: I modified it to add JupyterLab kernels to each new virtual environment. But if you
  11. :: don't use JupyterLab, then don't use this new version.
  12. ::
  13. :: If you need to remove a virtual environment in the future, simply delete its folder as
  14. :: usual, then run this from the commandline:
  15. ::
  16. ::      jupyter kernelspec uninstall venv_plotly
  17. ::
  18. :: Just replace "venv_plotly" with the kernel name - always lowercase.
  19.  
  20. REM Create the new 'venv' folder.
  21. set "PYTHON=%USERPROFILE%\Code\Python"
  22. set /P "PROJECT=New project name: "
  23. title [VENV] %PROJECT%
  24. set "PRDIR=%PYTHON%\%PROJECT%"
  25. set "ENV=%PRDIR%\venv"
  26. if not exist "%ENV%" (
  27.     mkdir "%ENV%"
  28.     REM Create the virtual environment.
  29.     echo Creating the virtual environment . . .
  30.     python -m venv "%ENV%" --upgrade-deps
  31.     set "CREATED=TRUE"
  32.     REM Create a new Python file.
  33.     echo #!python3>"%PRDIR%\run.py"
  34.     call :NPP
  35. ) else (
  36.     echo That project already exists.
  37.     pause
  38.     call :NPP
  39. )
  40.  
  41. REM Install some more libraries in the virtual environment.
  42. if "%CREATED%" == "TRUE" (
  43.     pushd "%ENV%\Scripts"
  44.     call "activate.bat"
  45.     python pip.exe install wheel
  46.     python pip.exe install ipykernel || REM Installs the JupyterLab kernel.
  47.     python -m ipykernel install --user --name="venv_%PROJECT%" || REM Adds the kernel to JupyterLab.
  48.     call "deactivate.bat"
  49.     popd
  50. )
  51.  
  52. REM Activate the virtual environment.
  53. cd "%PRDIR%"
  54. cmd /K "%ENV%\Scripts\activate.bat"
  55. goto :EOF
  56.  
  57. REM Open the new Python file.
  58. :NPP
  59. start "" /D "%PRDIR%" "C:\Program Files\Notepad++\notepad++.exe" "%PRDIR%\run.py"
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement