August 10, 2015
November 25, 2019
How to install pip, virtualenv and virtualenvwrapper on Linux
I don't know how much up-to-date is pip in repositories from other distributions but version in Ubuntu 15.04 is from about year ago.
sudo apt-get install python-pipeshlox@eshlox:~$ pip -Vpip 1.5.6 from /usr/lib/python2.7/dist-packages (python 2.7)
Because of this some commands don't work correctly.
eshlox@eshlox:~$ pip freezeException:Traceback (most recent call last):File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in mainstatus = self.run(options, args)File "/usr/lib/python2.7/dist-packages/pip/commands/freeze.py", line 74, in runreq = pip.FrozenRequirement.from_dist(dist, dependency_links, find_tags=find_tags)File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 299, in from_distassert len(specs) == 1 and specs == '=='AssertionErrorStoring debug log for failure in /home/eshlox/.pip/pip.log
Let's remove pip.
sudo apt-get remove python-pip
I think that better option would be to install current version of pip from official site. When it is possible I always prefer to install software in my user home directory, that's why --user flag appears below.
Let's install pip.
wget https://bootstrap.pypa.io/get-pip.pypython get-pip.py --userrm get-pip.py
eshlox@eshlox:~$ .local/bin/pip -Vpip 7.1.0 from /home/eshlox/.local/lib/python2.7/site-packages (python 2.7)
Pip is now installed in user home directory, executable file exists in ~/.local/bin. We should add this to \$PATH environment variable.
~/.bashrc file and add at the end:
Now we can just use pip in shell.
eshlox@eshlox:~$ pip -Vpip 7.1.0 from /home/eshlox/.local/lib/python2.7/site-packages (python 2.7)
We can simply upgrade pip when newer version will be available.
pip install pip --upgrade
In the same way we can install virtualenv and virtualenvwrapper.
pip install virtualenv virtualenvwrapper --user
Because we added ~/.local/bin to \$PATH, virtualenv and virtualenwrapper are available from command line.
eshlox@eshlox:~$ mkvirtualenv --version13.1.0
As described here, we should add shell startup file with our path to virtualenwrapper (.bashrc). It can look like this:
export WORKON_HOME=$HOME/projectsexport PROJECT_HOME=$HOME/projectssource $HOME/.local/bin/virtualenvwrapper.sh
Done. Everything works as it should, and we are not dependent on versions from system repository.