-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
On Mac/Linux:
source venv/bin/activate
On Windows:
.\venv\Scripts\activate
-
Upgrade pip:
pip install -U pip
-
Install ipykernel (if not already installed):
pip install ipykernel
-
Register your virtual environment with Jupyter:
python -m ipykernel install --user --name=venv --display-name="Python (venv)"
-
Select the kernel in your Jupyter notebook:
- Launch Jupyter Notebook
- Open your notebook
- Click on "Kernel" in the top menu
- Select "Change kernel"
- Choose "Python (venv)" from the dropdown menu
-
Now you can install and use dependencies within your virtual environment.
- If your kernel doesn't appear in the list, restart Jupyter Notebook
- To verify your virtual environment is active, check for
(venv)
at the beginning of your command prompt - To deactivate your virtual environment, simply run
deactivate