60

When trying to create a virtual environment using the included pyvenv-3.4 that comes with 14.04, it throws an error:

Error: Command '['/some/directories/bin/python3.4', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

How do I use pyvenv-3.4 with Ubuntu 14.04?

Ryan
  • 1,428

7 Answers7

52

Unfortunately, 14.04 shipped with a broken pyvenv. According to this launchpad thread the issue will be resolved in the upcoming 14.04-1

Using this method you can install a Pyvenv environment without pip and then manually install pip after the fact.

pyvenv-3.4 --without-pip myvenv
source ./myvenv/bin/activate
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-3.4.4.tar.gz
tar -vzxf setuptools-3.4.4.tar.gz
cd setuptools-3.4.4
python setup.py install
cd ..
wget https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz
tar -vzxf pip-1.5.6.tar.gz
cd pip-1.5.6
python setup.py install
cd ..
deactivate
source ./myvenv/bin/activate
Ryan
  • 1,428
47

Reason: Both Ubuntu 14.04 and Debian have a broken pyvenv-3.4 tool. See Ubuntu bug 1290847 and Debian bug 732703.

Solution/workaround (shorter than the one from the other answer):

pyvenv-3.4 --without-pip venvdir
source venvdir/bin/activate
curl https://bootstrap.pypa.io/get-pip.py | python
deactivate
source venvdir/bin/activate

I've described this bug in my own Gist. The URL in this code is from the official pip installation instructions.

11

This should work too:

sudo apt-get install python-virtualenv
virtualenv -p python3 myvenv

Or better yet:

sudo apt-get install python3-pip
sudo pip3 install virtualenv
virtualenv myvenv
3

You are missing the venv lib for python 3.4, just run:

$ apt-get install python3.4-dev python3.4-venv

Gregory
  • 131
0

The way I solved this is by running

$ python -m ensurepip

Which produced a stacktrace ending with this line:

FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib64/python3.4/ensurepip/_bundled/setuptools-20.10.1-py2.py3-none-any.whl'

So I went to https://pypi.python.org/pypi/setuptools/20.10.1 and grabbed the wheel and put it in my directory (which I had to create with mkdir -p /usr/lib64/python3.4/ensurepip/_bundled/)

Then running python -m ensurepip again I was confronted with

No such file or directory: '/usr/lib64/python3.4/ensurepip/_bundled/pip-8.1.1-py2.py3-none-any.whl

So I went to https://pypi.python.org/pypi/pip/8.1.1, grabbed that wheel and stuck it in the directory.

Now I can create virtualenvs with python -m venv .venv. Success!

Wayne Werner
  • 6,872
0

Tested on Debian

 
$ python3.4 -m venv --without-pip env
$ cd env
$ source ./bin/activate # virtualenv activated

$ wget https://bootstrap.pypa.io/get-pip.py # get installation script for pip
$ python3.4 get-pip.py
$ deactivate
$ source venvdir/bin/activate

$ pip list # just to check that pip works!

-1

I came across this error because I was missing the python3-venv package on my system.

Zanna
  • 72,312