OwnBlog from DimiG    About    Archive    RSS

Python Virtual Environment

The Python programming is a real adventure. I prefer to use it for small projects or fast developing stuff. Python packages empower the language. Every task demands the own set of packages. So, it is a good idea to separate it for every task.

At beginning I want to give one interesting quotation from one very interesting man: “Programming allows you to achieve and accomplish things that no ordinary human-being ever could, at amazing speed.” Harrison Kinsley (@Sentdex)

Because of I’m not looking for easy ways 😏, I use the Python on Windows platform and … I use it under Cygwin.
Believe the Cygwin, Python and package management system (pip) already pre-installed on your system. pip is a package management system used to install and manage software packages written in Python.

First of all you have to install the virtualenv and virtualenvwrapper by pip additionally. The next step is to go to /usr/bin/ and run the virtualenvwrapper.sh It will automatically create the .virtualenvs directory. If NOT you can create it yourself ;)
The further step is to write some configuration lines into your home .bash_profile:

export WORKON_HOME=$HOME/.virtualenvs
export PIP_VIRTUALENV_BASE=$WORKON_HOME
source /usr/bin/virtualenvwrapper_lazy.sh 

The virtualenvwrapper_lazy.sh located same place as a main file, but allow for faster load when your terminal start.

So now we are ready to make our environment by:

$ mkvirtualenv myProject

Then we can switch on it by:

$ workon myProject

By the way, to get a full list of available environments, type workon without an argument.

The other useful commands are deactivate to step out of the currently active environment, and rmvirtualenv to delete an environment.

Have a good day and Merry Xmas for all!