Stop thinking and use Anaconda for all Learnings

March 26, 2017

Written with love by

 

We all love having all things in the same place bundled. We love it so much that almost all retail industries have something which is delivered as a bundle.

 

Take mobile plans for an example - you have SMS, data and call time bundled. Programming is no different. Python can be installed as a silo and then packages can be imported as we wrote in one of our earlier blogs -

 

Top 5 Python packages every college student should know 

 

This blog takes a level further and will introduce you to the concept of Python distribution. Distribution is such a bundle which is made available for AI, Data science, Machine learning, Deep learning and robotics work. This provides three key advantages -

 

# Tested with modules as Tensorflow, Jupyter Notebook, Spark. So you don't have to worry much about interdependencies.

 

# Easy management by the cross-platform 'conda' which is actually written in python

 

# Create environments using conda and you can create, export, list, remove, and update environments that have different versions of Python and/or packages installed in them. Switching or moving between environments is called activating the environment.

 

You can even share an environment file with a coworker or friend.

 

How to get started? 

 

It is so simple that we will not detail it much in this blog. Just go to the website and download the Windows or the Linux version that you wish.

 

Since most of our blog followers are Windows based and we cater to student community we will refer to Windows in the rest of the blog. In case you are on Linux check the link at the bottom of this section.

You can create, export, list, remove, and update environments that have different versions of Python and/or packages installed in them using Conda

 

 

Tip: When you install there would be a prompt for download of the Anaconda cheat sheet.We personally like the cheat sheet so please go ahead and download that via email as well.But this is not mandatory. 

 

Anaconda download link (For both Windows and Linux - Use the tabs)

 

 

How to test if Anaconda is installed correctly?

 

You can do two simple tests. Please go to command prompt of Windows and type:

 

conda 

 

This will list out the Conda command options.

 

Now let us play a bit more with the conda commands as we would be using conda exclusively in the remaining blog post.

Now type in command prompt:

 

conda -- version

 

My laptop returned conda 4.3.14 as shown in the picture below.

 

What's next after Anaconda is installed and Conda is tested?

 

You would now need to create an environment which you will use for the Python version.The good thing is that you can choose the Python version.

 

Example: conda create --name MieRobotBlogTest python=3.4

 

Let us see this command word by word.

 

conda: This calls the conda cross-platform management


--name: Any name that you would like to call this environment. A good tip is to denote the Python version or work you plan to do

 

Python=3.4: We have selected the version here.If you need Python2 you can use that well as python=2.7.You can also install some packages here numpy in one go as:


conda create --name MieRobotBlogTest numpy

 

Ok, now go ahead and the prompt will show you the details of the installations to be performed and just type Y and hit enter.

 

The install will take some time to install and make sure you are connected to the internet. (I am not creating this environment as i already have two created on my laptop).

 

To activate use: activate <environment name>

 

activate MieRobotBlogTest

 

How to check if the environment has been installed correctly?

 

Simple. Type: conda info --envs


The image shows us the environment created. I have more than one so you see multiple environments.

 

How to install more packages like Jupyter notebook,matplotlib?
 

Simple just type: conda install <package name>


conda install jupyter notebook
conda install matplotlib

Type: conda info --envs
The image shows us the environment created

 

You are all set now with a Python Anaconda environment and also learnt to installed notebook and matplotlib with conda install command.Easy as a pie!

 

Ok, what's next we can do?

 

Well, let us now run a Jupyter Notebook session and use the kernel from this new environment. You would need to register the kernel of the new environment as(make sure you are now in the environment and this can be seen if your prompt shows the environment name shown in brackets):

 

python -m ipykernel install --name <Your environment name>
python -m ipykernel install --name MieRobotBlogTest

 

To open a notebook session type (make sure you are now in the environment and this can be seen if your prompt shows the environment name shown in brackets as below example):

 

(MieRobotBlogTest)  c:/user/Mierobot/ Jupyter notebook

 

Make sure your antivirus does not block python dll or popups. A session would open in your default browser. Open a new notebook and paste any matplotlib code.We modified a sample code if you are new to matplotlib.

 

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
ax = plt.subplot(111)

t = np.arange(0.0, 5.0, 0.01)
s = np.sin(7*np.pi*t)

red_patch = mpatches.Patch(color='blue', label='Mierobot Blogs')
plt.legend(handles=[red_patch])
line, = plt.plot(t, s, lw=2)

plt.annotate('sample sine wave', xy=(2, 1), xytext=(3, 1.5),
            arrowprops=dict(facecolor='black', shrink=0.05),
            )

plt.ylim(-2,2)
plt.show()

 

 

Press ctrl+enter to run the code and you see a sine wave with high amplitude which is now running over your new conda managed environment. 

 

In case, you wish to later delete this environment you can use the command:

 

conda remove --name <Your environment name> --all

 

conda remove --name MieRobotBlogTest --all

 

Warning : This will permanently delete the environment and you would need to do the above steps again if you want them back.

 

Hope this blog was helpful. Please share,comment and like. You may also tweet this blog by clicking below or the social media icons below.

 

What next can i do?

 

Congrats! You can start moving into areas of deep learning and machine learning now using Python distribution of Anaconda like the google Tensorflow. 

 

 

 

 

 References : http://matplotlib.org/users/legend_guide.html

https://conda.io/docs/using/envs.html#

http://matplotlib.org/api/pyplot_summary.html

 

 


 

Share on Facebook
Share on Twitter
Please reload

Please reload