To create a new environment with a specific Python version and be able to use Jupyter and Spyder from that environment (while Jupyter and Spyder are installed in your base environment), follow these detailed steps:
Open your terminal in WSL2 (or use Anaconda Prompt if on Windows).
Create a new Conda environment by running the following command. Replace my_env
with your desired environment name and 3.8
with your preferred Python version:
conda create --name my_env python=3.8
Confirm the installation of the packages when prompted by typing y
and pressing Enter
.
Once the environment is created, activate it by running:
conda activate my_env
Your terminal prompt should now show (my_env)
, indicating that the environment is active.
spyder-kernels
in the New EnvironmentSince Spyder is already installed in the base environment, you only need to install spyder-kernels
in the new environment:
conda install spyder-kernels
spyder-kernels
is required for Spyder to connect to the new environment and execute code, debug, and use features like the variable explorer.
To use Jupyter Notebook from your base environment with the new environment’s packages and Python version, you need to install ipykernel
in the new environment:
conda install ipykernel
After installing ipykernel
, register the new environment as a kernel in Jupyter:
python -m ipykernel install --user --name=my_env --display-name "Python (my_env)"
-user
: Registers the kernel for the current user.-name
: Sets a unique name for the kernel (e.g., my_env
).-display-name
: Sets the display name that will appear in Jupyter Notebook (e.g., Python (my_env)
).Launch Jupyter Notebook from the base environment:
jupyter notebook
In the Jupyter Notebook interface, go to Kernel
-> Change Kernel
and select Python (my_env)
.
Now, any code you run in this notebook will use the packages and Python version specific to my_env
.