Thursday, February 16, 2017

Journey to Linux(step 1 of n): Virtual Environment

Little about Python versions


Various versions of Python are available and it is one of the most widely used language in open source community. In Linux several system core packages are dependent on python. 

Currently python version 2.7 is widely used and thousands of packages are targeting it in different Linux distributions. If we want to check which python version is installed by default on system.

 

BUT what if we want to use some other python version?

Well its very common scenario that we want to test project with different versions. In order to use multiple python versions without conflicting each other Virtual Environment is the solution.

What is Virtual Environment Anyway?

e.g. Project A has dependency on Python 2.6 and Project B has dependency on 3.0. Both of these project dependencies are other then system default python version i.e. 2.7 here in this case.

What if we change the system default python version to our desired on. Well it is possibly suicidal mission because there are several core Linux packages have dependencies on it. So, answer is simply NO, we will try to blow ourselves doing this usually. Our answer to this problem is virtualenv.
Virtual environment is basically a tool to create an isolated python environment for different projects.
We can have many virtual environments if we have several such dependencies. Each virtualenv will create separate  folder for all required executables to use the desired packages of certain project would need.

How we are going to do this...

It is very easy and i will explain it in few steps below:

Step 1: In order to manage python package we have to install python-pip package manager.


Step 2: Install virtualenv 


 Step 3: Create virtual environment for project 


virtualenv will create a folder in current working directory that will contains pip and python executable files. pip can be use to install other packages.


We can also have python interpreter of out choice like this 


Step 4: Activate the virtualenv


The name of virtual environment will appear on left of prompt now. Now all packages that you install using pip will be placed in projEnvr folder that is quite isolated from global installation.


And when you are done with virtualenv deactivate it


It will put back to system default prompt. And we you want to delete virtualenv then simply delete the folder.





Little bit about my windows addiction

I am professional Software Engineer and mostly using .NET and SQL Server for my work. Like many home users and developers i fell in love with Windows because it too easy and i was quite reluctant to accept any challenge.

Only thing that i love about Windows is .NET framework and C# language it is quite promising for my work. It is the only reason that i took so long to stay there. But now i want to grab some new challenges like python, nodejs and GIT etc in my skill set. 

BUT now guess what ...


Well i am using windows OS for last 16 years, experienced all versions from Windows 98 to  Windows 7 until now. I really tell you what i am fade up from windows now completely because as times passes my machines getting slower and slower. Update Manager is always running and install several hundred MB of new patches.
 
I hope this journey will be quite challenging in beginning because i am NOT very use to with commands line philosophy . But i love to control my machine and want to join the community of REALLY free people. I love you guys :).

Cheers