Using Conda Python Environments with Spyder IDE and Jupyter Notebooks in Windows

Prem George
4 min readOct 2, 2020

--

Requirements for following the steps:
> We need Anaconda Installed, link for that
https://www.anaconda.com/products/individual
> select the version to download and install

1. Creating new environment with pip

This step has lot of help everywhere, just to refresh up
Use Anaconda Prompt for the following steps:
> Check the available environments
conda env list

this will list all the available environments that are created before.

> To create an new environment:
conda create -n env_name
or with python version
conda create -n env_name python=3.7.4

> When conda asks you to proceed, type y

> Once created we see

> To activate the environment, type
conda activate env_name

> Now we can do pip install packages
> Check the list of environments

> To get the path of the new environment
python -c “import sys; print(sys.executable)”
This is the path to be used in Spyder python interpreter to change the environment for spyder

> To deactivate the environment (no need for env_name)
conda deactivate

> To delete an environment
conda remove -n env_name --all

2. How to use the new environment in Jupyter

> To set the conda environment for jupyter,
First we have to install kernel
install ipykernel inside the environment with following cmd
conda install -c anaconda ipykernel

> proceed y to continue

> check the installed kernel specs with the following cmd
python -m ipykernel install --user --name=env_name

> Run Jupyter Notebook as
jupyter notebook

Open the jupyter browser , you can see the new environment in the ‘New’ dropdown,

selecting that will open a new notebook, to confirm the environment, type
import sys
print(sys.executable)

3. How to use the new environment in Spyder

> To set the conda environment for Spyder,
First we have to install kernel
install spyder kernel inside the environment with following cmd
pip install spyder-kernels

> Get the path of the new environment as we did before, copy the path

> Now open the spyder IDE, under the console, at the bottom we can see the current environment, it should be conda base environment like

> To change that, Open Tools -> preferences

> in python interpreter, which is set as default initially

> select the “Use the following Python interpreter:” and paste the path as below and click Apply and OK

> now we can use the new environment in spyder

> To check the environment, restart the kernel from the console like below

> run the code
import sys
print(sys.executable)

Hope this helps :)

Thanks for reading…………

--

--