Setting up Python environments using Anaconda
Tags: beginners, tutorial, python, deeplearning
Published: 2020-11-13 19:10:01

## 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](https://www.anaconda.com/) and select the _Individual Edition_ tab under the products dropdown.

![8](https://dev-to-uploads.s3.amazonaws.com/i/orz5wntlz1hnauzfbl1z.png)

or simply click this [link](https://www.anaconda.com/products/individual)

Now click the **Download** button

![9](https://dev-to-uploads.s3.amazonaws.com/i/n6ximwg30q9igmwkuhuh.png)

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

![10](https://dev-to-uploads.s3.amazonaws.com/i/3aqig9lb41m6ozo9m0zr.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/jnweadtb8gvm7d03rrbu.PNG) 

Incase of any difficulty with this step you can view the official documentation for installing Anaconda [here](https://docs.anaconda.com/anaconda/install/).

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](https://dev-to-uploads.s3.amazonaws.com/i/jm2clw7c4vw66s2eooit.png)

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

![15](https://dev-to-uploads.s3.amazonaws.com/i/gn3nwejz7due4f2tf907.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/sfz47rax5e992diu1xwf.PNG)

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

![17](https://dev-to-uploads.s3.amazonaws.com/i/5k9pc2d7jit0vra5hv2r.PNG)

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](https://dev-to-uploads.s3.amazonaws.com/i/ympl0tizhrnzcgjuyqoz.PNG)

Notice how you are viewing the _installed_ packages. 

![19](https://dev-to-uploads.s3.amazonaws.com/i/ejp9oyotwlnumn3dqk8h.PNG)

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](https://keras.io/)).

![20](https://dev-to-uploads.s3.amazonaws.com/i/xpc79m4aiqm6r8hb6omi.PNG)

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

![21](https://dev-to-uploads.s3.amazonaws.com/i/3xhn2xqcq4cgxohldtjo.PNG)

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](https://dev-to-uploads.s3.amazonaws.com/i/af48kgo1b3s61t314tj0.png)
 
Once the prompt opens, type in the _activate_ command followed by the name of your environment (this name is case sensitive).

![23](https://dev-to-uploads.s3.amazonaws.com/i/h34j5ri80c43bmm7xmyo.PNG)
 
Now you can see that the environment updated from _base_ to your environment. 

![24](https://dev-to-uploads.s3.amazonaws.com/i/myqw9ilfrf55b91kb2oo.PNG) 

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](https://dev-to-uploads.s3.amazonaws.com/i/rhvq60undfeedisi2okn.PNG)

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

![26](https://dev-to-uploads.s3.amazonaws.com/i/8yxpng04abr4ytzhmc39.PNG)

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!