DEV Community

Dendi Handian
Dendi Handian

Posted on • Edited on

Creating New Environment in Anaconda

Open the Anaconda Prompt

If you're using Windows machine, you can find it directly using search on Start menu and type anaconda. You should see the anaconda prompt shortcut and click it to open.

anaconda prompt search menu

Or you can open Anaconda Navigator and launch the CMD prompt from there.

cmd anaconda

Explore the Current (Base) Environment and Conda Command

When you in the anaconda prompt at the first time, you will use the default (base) environment. To make sure any conda command will work later, check it with:



conda -h


Enter fullscreen mode Exit fullscreen mode

And you should see the information of available conda commands, like:

  • conda --version to check the current anaconda version
  • conda list to see the list of packages installed in the current environment
  • conda env list to see the list of environment (we'll create one later..)

Creating New Environment

I'm testing this on September 2021. So I'm planning to use the latest version of python but actually use the previous one of the latest. At the time, latest python version is 3.9.7 and the latest version of the previous one is 3.8.12. So the command for creating the new environment for me is:



conda create -n sep_2021 python=3.8


Enter fullscreen mode Exit fullscreen mode

The sep_2021 above is the name of environment (you can use yours) and the python=3.8 will make the env using the latest python 3.8 version. After the env created, we could check it using conda env list to make sure it really created.



(base) C:\Users\dendi>conda env list
# conda environments:
#
base                  *  C:\Users\dendi\anaconda3
sep_2021                 C:\Users\dendi\anaconda3\envs\sep_2021


Enter fullscreen mode Exit fullscreen mode

Activating and Using the New Environment

We could easily use the new environment by this command:



activate sep_2021


Enter fullscreen mode Exit fullscreen mode

You will notice it will change from base to sep_2021 in the CMD. If you check the conda list now, it will show this list:



(sep_2021) C:\Users\dendi>conda list
# packages in environment at C:\Users\dendi\anaconda3\envs\sep_2021:
#
# Name                    Version                   Build  Channel
ca-certificates           2021.7.5             haa95532_1
certifi                   2021.5.30        py38haa95532_0
openssl                   1.1.1l               h2bbff1b_0
pip                       21.0.1           py38haa95532_0
python                    3.8.11               h6244533_1
setuptools                58.0.4           py38haa95532_0
sqlite                    3.36.0               h2bbff1b_0
vc                        14.2                 h21ff451_1
vs2015_runtime            14.27.29016          h5e58377_2
wheel                     0.37.0             pyhd3eb1b0_1
wincertstore              0.2                      py38_0


Enter fullscreen mode Exit fullscreen mode

The above list is the default packages installed when we create new environment. Noticed something?

Yes! We need packages like numpy, pandas, matplotlib, seaborn, etc for our data science work. We can install those packages manually.

Installing Data Science Related Packages to the New Environment

You can install the packages one by one with pip commands like pip install numpy and then pip install pandas, but you can directly install them all at once like this:



pip install numpy pandas matplotlib seaborn


Enter fullscreen mode Exit fullscreen mode

And you may want to add another as your need.

Using the New Environment for Jupyter Lab & Notebook

When you look at the Anaconda Navigator interface now, you will see the new environment listed:

Alt Text

You can select it and launch the jupyter lab or jupyter notebook with the new environment

Top comments (0)