When installing Python software, sudo easy_install and sudo pip are something you should do very seldom. sudo means you are messing with your operating system files. easy_install means that it is easy to install, but impossible to uninstall. You most likely step on the toes your operating system package manager and make your Python installation damaged – damaged in a way you cannot reliably use OS package manager to install or upgrade the software in the future. There is also a high chance that two software depends on the different version of a library X and easy_install will happily overwrite anything with different version in your system.
Even though being badly broken, still plenty of Python software documentation recommends sudo easy_install as an installation method.
virtualenv is a Python tool for creating an isolated Python environment for a normal user. They are isolated in a sense, that only the software you install there will see and mess with the environment. When you are running virtualenv’ed python, pip and easy_install can freely pull in any libraries from pypi without the worry that you break some other software on your computer.
Here is a recipe for installing virtualenv’ed Python software which should across UNIXes and Windows. It will totally run as your normal user privileges, no sudo or admin needed. Only an installed Python interpreter and a working python command are the requirements.
So fire up your console, go the folder where you wish to perform the installation and type the following (some commenting added to explain the process):
# First create the folder where you wish to install the software # with mkdir command. Then go to this folder with cd command. # Windows users: Please manually download virtualenv.py # to the target folder ith your web browser. UNIX users # can use curl command line downloader as below. # Note: Don't rely on operating system virtualenv command. # It might be hassle to instruct virtualenv package installation # due to distribution flavours. # Old Ubuntus ship really old virtualenv.py and it has not worked # on all cases. # Github virtualenv.py is the msot reliable method. curl -L -o virtualenv.py https://raw.github.com/pypa/virtualenv/master/virtualenv.py # Create a virtualenv environment # where the software and its dependencies # will be pulled from PyPi. In our case # we call the created virtualenv folder "venv" python virtualenv.py venv # Activate the virtualenv environment. # This will set your PATH environment # variable so that following "python" # command executes from under the virtualenv, # not from your global system setup. # # Windows equivalent: .\venv\Scripts\activate . venv/bin/activate # Now when virtualenv is activated, # pip and easy_install will install any software # under this virtualenv environment, not on your operating system files pip install YOUR_PACKAGE_NAME_ON_PYPI.PYTHON.ORG # Usually, if you install Python command line software, # new launcher scripts get created in venv/bin # folder. When venv environment is active, # this folder takes precedence in PATH environment # variable. Meaning, when you have virtualenv activated # you can simply type in the installed command name # without full path to execute it.
And again with a real life example:
curl -L -o virtualenv.py https://raw.github.com/pypa/virtualenv/master/virtualenv.py python virtualenv.py vvv-venv . vvv-venv/bin/activate pip install vvv
- Don’t use UNIX shell source command as it is not standard. Use . instead.
- curl is available on OSX by default. wget is alternative, but not available on all systems out of the box.