python datamining packages virtual environment setup in ubuntu

main1

virtual Environment:

Virtual Environment is to create a python environment which allows using different python modules & versions, without messing up the system.

let’s understand virtual environment with its need in the project development. In the world of python projects, it’s obvious to use different python libraries (wrappers) to get our work done, but It won’t be happy ending all the time. Most of the time we face environment issues where our python application won’t run on new machines(computer systems). This is because of the dependence issue of python libraries on the new machine (in which we try to run our python application). For better understanding, suppose in the development face in our python application we have used python pandas (Python data analysis library) version 0.18.0 function which was not there in pandas 0.17.1. In new machine pandas version 0.17.1 we installed. So the python application won’t run on the new machine because of the version difference.

To overcome this, we need to use an created python environment which contains everything that a Python project (application) needs in order to run in an organized, isolated fashion.

So Using virtual Environment is the recommended way for working with Python projects, regardless of how many you might be busy with.

In ubuntu creating virtual environment is much easy by using virtualenv (a tool to create isolated Python environments)

About virtualenv:image02

Virtualenv helps solve project dependency conflicts by creating isolated environments which can contain all the goodies Python programmers need to develop their projects. A virtual environment created using this tool includes a fresh copy of the Python binary itself as well as a copy of the entire Python standard library.

Installing virtualenv:

$ sudo pip install virtualenv

As of now we successfully installed virtualenv. Now let’s create a folder (Environment) where we will  install python data mining packages .

Create  virtual environment:

 

$ virtualenv dataaspirant_venv

virtualenv dataaspirant_venv will create a folder in the current directory which will contain the Python executable files, and a copy of the pip library which you can use to install other packages. The name of the virtual environment (in this case, it was dataaspirant_venv) can be anything; omitting the name will place the files in the current directory instead.

This creates a copy of Python in whichever directory you ran the command in, placing it in a folder named dataaspirant_venv

Using the virtual environment:

To use the virtual environment, it needs to be activated

$ source dataaspirant_venv/bin/activate

 

The name of the current virtual environment will now appear on the left of the prompt (e.g. (dataaspirant_venv)Your-Computer:your_project UserName$) to let you know that it’s active. From now on, any package that you install using pip will be placed in the dataaspirant_venv folder, isolated from the global Python installation.

Python Data mining packages Installation:

So let’s start installing data mining python packages one by one

Numpy installation Command:

 

$ pip install numpy

Scipy Installation Command:

$ pip install scipy

Matplotlib Installation Command:

$ pip install matplotlib

Ipython Installation Command:

$ pip install ipython[all]

Pandas Installation Command:

$ pip install pandas

Statsmodel Installation Command:

$ pip install statsmodels

Scikit-learn Installation Command:

$ pip install scikit-learn

Running Script File:

when virtualenv is in the active mode you simple go the directiory where your python script file there and run your script file in the general way.

$ python script_file.py

Deactivate the virtual environment:

If you are done working in the virtual environment for the moment, you can deactivate it.

$ deactivate

This puts you back to the system’s default Python interpreter with all its installed libraries.

To delete a virtual environment, just delete its folder. (In this case, it would be rm -rf dataaspirant_venv.)

Reference Links:

[ 1 ] http://docs.python-guide.org/en/latest/dev/virtualenvs/

[ 2 ] https://en.wikipedia.org/wiki/Virtual_environment_software/

Follow us:

FACEBOOK| QUORA |TWITTERREDDIT | FLIPBOARD |LINKEDIN | MEDIUM| GITHUB

I hope you liked today’s post. If you have any questions then feel free to comment below.  If you want me to write on one specific topic then do tell it to me in the comments below.

If you want to share your experience or opinions you can say.

Hello to hello@dataaspirant.com 

THANKS FOR READING…!

7 Responses to “python datamining packages virtual environment setup in ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *

>