Python Environments Management in Anaconda Navigator

Marius Safta
Cluj School of AI
Published in
4 min readMar 26, 2019

--

Hello World!

In the previous article we installed Anaconda and successfully set up a Python dev environment. The importance of having a separate virtual environment for each project was also touched upon. As a reminder, allow me to cleverly quote myself:

“Keep in mind that several libraries are needed, each requiring dependencies, meaning you’ll have a lot of packages being installed and updated. Ideally you shouldn’t have everything in the single Python installation and create all your projects in it. Instead, every project should have its own separate virtual environment in the Python installation with only the necessary packages installed.”

“I realize it can be daunting for beginners and may seem an unnecessary complexity. As a best practice however, it is very positive to do this from the start.”

Creating a new Environment in Anaconda Navigator

Anaconda Navigator makes creation and management of multiple virtual environments a simple affair.

In the Environments section you’ll see the environment list. When you installed Anaconda, the base (root) environment was created by default.

The base environment displaying the list of installed packages

As you can see in the above image, a list of all installed packages is shown.

To create a new environment, press the Create button. In the pop-up window, enter a name for your environment (preferably something descriptive of its purpose) and choose a Python version to use (3.6 and up).

Creating a new environment with Anaconda Navigator

Finally, press Create in the pop-up and Anaconda will proceed to create the new environment, which presents the most basic packages. To really make use of this environment we’ll need to install other packages.

Installing packages in Anaconda Navigator

One essential package for any Machine Learning project is Numpy, which implements a N dimensional array that is widely used in working with data. Numpy will get its own article, or series, but for now, let’s install it in Anaconda Navigator and do a quick test.

First thing, all packages need to be displayed in the list, not just the installed ones, so in the dropdown filter, select All.

Changing the package list filter to display all, instead of just installed ones

Once all packages are in the list, search for “numpy”, select it in the results and press the Apply button in the lower right side of the UI.

Selecting to install numpy from the list of available packages

A pop-up with dependencies will be displayed. This indicates all the other packages which numpy requires. Any missing packages from the environment will also be installed.

Now press Apply and all packages will be installed…

Test in Spyder

To make sure everything is working, let’s do a simple test using Spyder.

Heading back to the Home section, you’ll notice that Spyder needs to be installed again. This is one of the main reasons some don’t work in multiple environments, the need to install even the common things on each one. However, the long-term benefit of being resilient to possible conflicts down the road, which might cause projects to stop working very much makes up for a slight inconvenience in the beginning.

Press Install on Spyder, then launch it when it’s ready. In the left side paste the following code:

import numpy as npa = np.array([1,2,3])print(a)

After running this simple script, you should see “[1,2,3]” in the Python console on the right side.

Testing a numpy array with Spyder

Conclusion

We have successfully created a new Python environment and installed the Numpy package and its dependencies.

The next article will feature PyCharm be JetBrains, one of the most popular Python IDEs, which also feature easy environment creation and package installation.

Your opinions, feedback or (constructive) criticism are welcomed in discussions below or at @mariussafta

Join our Facebook and Meetup groups and keep an eye out for discussions and future meetups.

--

--