DEV Community

Cover image for Setting up Python environments using Anaconda
Muiz Alvi
Muiz Alvi

Posted on • Updated on

Setting up Python environments using Anaconda

Objective

This tutorial will help programmers setup their first python-based environment using a powerful open-source distribution known as Anaconda.

Table of Contents

  • Introduction
  • Acquiring Anaconda
  • Creating a new Environment
  • Adding packages to your Environment
  • Activating your Environment
  • Testing your Environment
  • Conclusion

Introduction

Students starting out with advanced data science fields, especially deep learning, often struggle with code implementation while making use of libraries. I have often observed programmers install a number of libraries each time they build a solution, only to reinstall these libraries whenever they restart their builder or system. This is slow, inefficient and quite an irritable process. Anaconda is a powerful open-source distribution that not only provides over 10,000 python libraries at a user's disposal but the feature of compartmentalizing and preloading any number of library packages in the form of environments. A user can now simply build an environment, download the libraries to this environment and use them whenever.

Acquiring Anaconda

Anaconda is free for individual use but if you have a company of over 200 employees then it is recommended to purchase a commercial license. Below is a two-step guide for downloading and installing Anaconda.

Step 1: Download

For this step, simply visit the Anaconda website and select the Individual Edition tab under the products dropdown.

8

or simply click this link

Now click the Download button

9

This will navigate you to the lower part of the tab where you can choose an installer according to your device.

10

Clicking a link will download the installer.

Step 2: Install

Clicking the downloaded file will start the installation wizard. The installation is fairly simple and the installation wizard will walk you through this process with ease.

13

Incase of any difficulty with this step you can view the official documentation for installing Anaconda here.

Once on this page, you can choose the guide for your operating system from a number of given hyperlinks.

Creating a new Environment

Navigate to where you installed Anaconda. You will see a variety of Anaconda related applications there. Windows users can simply view all this from the start menu.

14

Once in the desired folder or menu, open the Anaconda Navigator

15

In the navigator, click on the Environments tab. On the left you will see a list of environments and on the right you can see the python packages included in each environment.

16

Click on the Create button in the lower part of the list of environments, this will open a prompt.

17

Inside this prompt, give an appropriate name for your environment and click the create button. Now wait for your environment to be created.

Adding packages to your Environment

Now that you have successfully created an environment, it is important to install some python packages to this environment. These packages can then be accessed using any IDE or solution builder being used by your environment, more on this later.

To add packages, simply click on your environment (my environment is called irisproject) and view the installed packages on the right side.

18

Notice how you are viewing the installed packages.

19

From the drop down select not installed and use the search packages bar to search for a package. I will be installing Keras (you can learn more about this library here).

20

Now select the package or packages you wish to install and click apply on the lower right of the screen.

21

You have now successfully installed a package to your environment.

Note: You should also install Jupyter Notebook, Spyder and/or any other IDE using the steps mentioned above. These are all categorized as packages and are installed to an environment using the same steps I have used to install Keras.

Activating your Environment

You can access and make use of your environment in a variety of different ways. However, I will show you the fastest and simplest method of activating your environment. Simply open the Anaconda Prompt.

22

Once the prompt opens, type in the activate command followed by the name of your environment (this name is case sensitive).

23

Now you can see that the environment updated from base to your environment.

24

You have successfully activated your custom environment!

Testing Your Environment

Now let's see if we can make use of the packages we installed in one of the previous steps. Use the Anaconda Prompt to open an IDE, if you haven't installed an IDE in your environment then do it now using the same steps for adding packages to your environment. I will be using Jupyter Notebook. Simply type in the name of the IDE to open it.

25

Create a new notebook or workspace (depending on the IDE you're using) and then import a package as I've done below.

26

As you can see, the package has been imported successfully and now we have an ideal solution environment that does not require us to install libraries each time it is used. You can now install new packages to the navigator and use them with ease.

Note: You do not have to create a new environment each time you wish to install a new package, simply add said package to the environment using the Anaconda Navigator.

Conclusion

You should now be able to create and modify your own environment(s) using Anaconda. I hope the tutorial was clear and covered everything, please use the discussion/comment section to let me know if you faced any difficulty or if any step is unclear.

Thank You for reading!

Top comments (2)

Collapse
 
andykneeland profile image
Andrew Kneeland

Remember if you are at a company with 10 or more people do not install the Anaconda Individual Edition, it is for academics and home use, it is NOT FREE. Anaconda may approach you to purchase their Teams or Enterprise Editions if you are above 10 users in one company. Just some friendly advice.

Collapse
 
muizalvi profile image
Muiz Alvi

Thank you so much for the friendly advice and yes I have mentioned this point under the 'Acquiring Anaconda' section of the post. The individual license is for individual use and I read somewhere that a company of 200 or more people should purchase the commercial license (mentioned in my post as well). I was confident with this statement at first, seeing as how Anaconda is partnered with companies like Nvidia, Intel, IBM... and so on (see full list here: anaconda.com/partners), but seeing your comment has made me question the credibility of my source. Anyways, I will check up on this statement again and edit the post accordingly.