Learn Python, Machine Learning

You use Python Environments with Conda ? here is how to manage them- part 1-

Hi what’s up everyone in this article I’m going to do a walk-through of anaconda and Conda virtual environments so for those who don’t know anaconda is a Python package installer. The advantage of a package installer like nanaconda is with the one install you’re getting Python but with a ton of packages a ton of the core packages that people use especially for scientific computing.

 So it’s great for beginners because it’s very straightforward, once install all the packages you need no confusion and yeah. so if you want to start with anaconda you just come to their page you can just search Google for anaconda come down to the downloads

And pick your install either 3.6 or 2.7, so once you have that installed you’re ready to go. So if you open up a command window you can type Python and you start an interactive Python shell in your command window,  so you can see I have Python 3.5 with anaconda 4.2 installed.

 I can go ahead and do my Python stuff like :  import numpy and import pandas and you know off I go so that’s good.

But let’s say you want to have different versions of Python, or for example say you’re working with a group and you want to make sure everyone has the same version, everyone is working on the same version of Python, everyone has the same packages installed, so for a situation like this the Conda environments are really useful so if you want to create a content environment you just use the command Conda create – -name, give it a name for example project 1,  and then let’s specify let’s say we want version 3.5 and then we specify the packages we want.

 So what this does is conduct create means create the virtual environment the name, flag means that the next thing here is going to be the name of the environment and then you specify the version of Python. if you don’t specify the version of Python it’s going to default to the highest one which is currently 3.6 and then you specify the packages you want.

So now look let’s also install numpy as well, so it’s going to go ahead and create the new environment.  if we want to use our environment the command is to activate so you just type activate and then you give it the name project 1

So when it activates it it adds the project name, so that way you know that’s the project or the package or the environment you’re using,  so now if you go ahead and type Python

 It opens up a Python shell in our command window and we can import numpy because we installed that package,  but if we were to import pandas we’ll get a import error because we don’t have pandas. so with this package we can go and use pip to install stuff,  so let’s say while we’re acting we have the environment activator,  we can do pip install matplotlib, it’s going to go ahead and download matplotlib.

So now if we do Python and for Matplotlib,  there’s no import error so then you can all make sure you guys are working on the same version of Python and packages.

 So let’s say we want to create a environment with a different version of Python,  let’s say we want to do a Python 3.6 version or let’s do Python 2.7.  so go ahead and deactivate so the deactivate means go back to the root environment, so that’s like your default environment .

Let’s do the same commands :  we do conda create – – name i-27 Python  2.7 pip numpy

It doesn’t take too long,  and so now that we activate Py27, we can type Python you can see we’re using Python 2.7 now and we if we import numpy we have it because we specified it and while this is activated we can go and do pip install whichever package we need to you know get whatever package we need.

If you like this article, follow us in our facebook page : the over day and let’s your friends know by sharing it on social media.