How to Create New Environments in Anaconda

Pasupulati Rajesh Babu
4 min readMay 22, 2020

--

Installing Anaconda — Step 1

I recommend you download the Python 3.7 version. If you already have Anaconda installed

Anaconda can be downloaded here:

Installing Anaconda on mac os

Installing Anaconda on windows

Running Anaconda — Step2

Creating A New Environment — Step 3

You can create a new environment with the following command. After -n is where we specify the environment name. This is followed by the version of python we want to install.

conda create -n tensorflow python=3.7
After run that command type y and enter

We then need to activate our environment. The commands differ slightly between Windows and Mac. After entering the command, you should see that (base) has now changed to (your environment name). This means that any commands entered from this point on will be executed within that environment.

For mac :

source activate tensorflow

For Windows:

conda activate tensorflow

If you want to know your environment directory, you can find it via your OS file system. For example my file path looks like this.

cd /opt/anaconda3/envs

Installing a Python Kernel — Step 4

We need to create a Python Kernel inside of our environment so that we can run our code. Anaconda used to create a kernel by default. However, this is no longer the case, so we must do it manually.

​First we need install ipykernel:

pip install ipykernel

We now need to install a kernel. Again, make sure you have activated your environment, (tensorflow), in this case. To install a kernel, enter the following command. The variables after ‘ — name’ and display-name will need to be set to the name of your environment. If entered correctly, you’ll see a response ‘Installed kernelspec’.

python -m ipykernel install — user --name tensorflow --display-name “tensorflow”
python -m ipykernel install — user — name tensorflow — display-name “tensorflow”

Jupyter Notebook Setup — Step 5

After creating a new environment, we essentially start from scratch with an empty environment. Therefore, to use Jupyter Notebook we will need install it via Anaconda. Again, make sure you have activated your new environment.

conda install jupyter
Type y and enter

After installing Jupyter, we can now launch Jupyter Notebook with the following command:

jupyter notebook

After entering the command above, a Jupyter notebook server should launch via your default browser.

Make sure you are using the correct kernel!

This is where most people go wrong. After creating a new notebook, look at the top right of the screen. Ensure you have the correct kernel selected (i.e. the kernel we just installed to our environment.) If your kernel is not correct, you change kernel manually as shown below.

--

--