Virtual Environments & Jupyter Notebooks
Poetry
# Initialize Poetry - Set details + Dependencies
poetry init
# Initialize Poetry without giving any details
poetry init -n
# Set dependencies manually:
poetry add requests
# Or (Use carefully):
poetry add $(cat requirements.txt)
# IMPORTANT: Add the program name (Without .py) in pyproject.toml, with no _ or - in its name.
# Install the poetry Package
poetry install
# To Run the program from anywhere, just:
poetry --directory /path/to/program/ run /path/to/program/app.py
# Or just alias this last command..
Note: it is not necessary to add a shebang line to the Python program
Jupyter Notebook Themes
Having Jupyter Notebook not running:
pip install jupyterthemes
jt -l # List existing themes
jt -t monokai # Set an existing theme
venv + Jupyter Notebook = 💎
(Using Jupyter Notebooks under a virtual Environment)
# 1. Make sure ipykernel is installed
pip install ipykernel
# 2. Activate a venv:
python -m venv my-venv
# 3. WHILE having the venv activated:
python -m ipykernel install --name=my-venv
It should become available in Jupyter Notebooks now:
Using Venv in different OS
Linux:
pip install virtualenv
python -m venv my_venv
. my_venv/bin/activate
which python # Validation
deactivate
Windows: (NOT powershell)
pip install virtualenv
python -m venv my_venv
.\my_venv\Scripts\activate.bat
where python # Validation
deactivate
Pyenv → clean and organized Python environment
Manage multiple Python versions on a single machine. Switch between different Python versions, create isolated Python environments, and install packages specific to each Python version. Having multiple Python installations coexisting without conflicts, we can work with different Python projects that require specific versions or dependencies.