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?

up vote 49 down vote accepted

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
  • Someone suggested a radical edit to use get-pip.py in this answer - I think that is too much change, but please add your solution as a new answer (even just copying the upper part of this answer)! – Volker Siegel Sep 26 '14 at 13:19
  • What directory are you in when you run these commands? That is, is this the directory you will be building your python app in or do you have to cd into 'myenv' for that. Or, why are you creating a sub-directory for the environment? Dumb questions, but I've never used this before and there are too many different answers. At least your answer has one downloading from the python.org site and not some github repository I've never heard of. I'm a bit paranoid about stuff like that. – Bill Rosmus Nov 25 '14 at 3:18
  • anyway this appears to work so thanks. :) – Bill Rosmus Nov 25 '14 at 3:43
  • 3
    This remains broken in 15.04 as well. – knite May 26 '15 at 7:27
  • 3
    This remains broken in 14.04.2 LTS – tamakisquare Jul 12 '15 at 23:10

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.

  • 4
    You need to prefix 'sudo apt-get install python3.4-venv' - Otherwise I don't have a 'pyvenv-3.4' executable on the PATH. (Ubuntu 15.04) – Jonathan Hartley Jun 14 '15 at 15:07
  • @JonathanHartley: True. However, the bug mentioned in this question/answer is not present in Ubuntu 15.04, so the workaround in this answer is not necessary. – Denilson Sá Maia Jun 15 '15 at 15:35
  • Curious. I got here because I am seeing the problem in 15.04. Ah. The last few entries on the lengthy Ubuntu bug you link say one needs to install new package python3-venv, which isn't a dependency of python3, to get the fix. – Jonathan Hartley Jun 16 '15 at 9:04
  • @JonathanHartley: Your error message must be different than the error message from the question. Your error message must be pyvenv-3.4: command not found. And, yes, installing python3-venv is the solution for your error. – Denilson Sá Maia Jun 16 '15 at 11:21

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

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

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

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!

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!

  • Debian is off-topic here though... – Zanna Mar 7 '17 at 9:13
  • Sorry about that. I was hoping that it will be useful as a data point since Ubuntu uses Debian as a base. I could try in my Ubuntu VM later – razorsniper Mar 8 '17 at 2:40
  • That would be great :) – Zanna Mar 8 '17 at 5:09

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

  • 1
    Please can you state how to install it so others can use it when needed. – George Udosen Jan 3 '17 at 5:26

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.