Python's venv problem with ensurepip in Ubuntu

#Ubuntu #Python

Table of Contents

Ubuntu 14.04's Python 3.4 installation has a problem with ensurepip module, as described in this bug. So if you follow the steps mentioned in the official documentation, you would see an error message like this

1➜  Python  python3 -m venv py3.4venv
2Error: Command '['/home/thefourtheye//py34venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

To resolve this problem, first install the venv, without pip, like this\\

1python3 -m venv py3.4venv --without-pip

And then if you install pip, like this, it will still fail

1(py3.4venv) ➜  py3.4venv  python -m ensurepip --upgrade
2/home/thefourtheye/Python/py3.4venv/bin/python: No module named ensurepip
3(py3.4venv) ➜  py3.4venv  python
4Python 3.4.0 (default, Apr 11 2014, 13:05:11)
5[GCC 4.8.2] on linux
6Type "help", "copyright", "credits" or "license" for more information.
7...

So, you need to install, pip separately, like mentioned in the pip's official documentation. So, the actual list of steps go like this\\

 1➜  Python  python3 -m venv py3.4venv --without-pip
 2➜  Python  cd py3.4venv
 3➜  py3.4venv  source bin/activate
 4(py3.4venv) ➜  py3.4venv  wget https://bootstrap.pypa.io/get-pip.py
 5--2014-12-30 14:35:34--  https://bootstrap.pypa.io/get-pip.py
 6Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 103.245.222.175
 7Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|103.245.222.175|:443... connected.
 8HTTP request sent, awaiting response... 200 OK
 9Length: 1581355 (1.5M) [text/x-python]
10Saving to: ‘get-pip.py’
11
12100%[=====================================================================================================================>] 15,81,355    129KB/s   in 8.9s
13
142014-12-30 14:35:43 (173 KB/s) - ‘get-pip.py’ saved [1581355/1581355]
15
16(py3.4venv) ➜  py3.4venv  python get-pip.py
17Collecting pip
18  Downloading pip-6.0.3-py2.py3-none-any.whl (1.3MB)
19    100% |################################| 1.3MB 139kB/s
20Collecting setuptools
21  Downloading setuptools-9.1-py2.py3-none-any.whl (552kB)
22    100% |################################| 552kB 180kB/s
23Installing collected packages: setuptools, pip
24
25
26Successfully installed pip-6.0.3 setuptools-9.1
27(py3.4venv) ➜  py3.4venv  deactivate
28➜  py3.4venv  source bin/activate
29(py3.4venv) ➜  py3.4venv  pip install django
30Collecting django
31  Using cached Django-1.7.1-py2.py3-none-any.whl
32Installing collected packages: django
33
34Successfully installed django-1.7.1
35(py3.4venv) ➜  py3.4venv  which pip
36/home/thefourtheye/Python/py3.4venv/bin/pip
37(py3.4venv) ➜  py3.4venv