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?

1

7 Answers 7

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
5
  • 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)! Sep 26, 2014 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. Nov 25, 2014 at 3:18
  • 4
    This remains broken in 15.04 as well.
    – knite
    May 26, 2015 at 7:27
  • 4
    This remains broken in 14.04.2 LTS Jul 12, 2015 at 23:10
  • Not quite an Ubuntu issue, but I have the same issue with Miniconda. Dec 21, 2016 at 23:55
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.

4
  • 5
    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) Jun 14, 2015 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. Jun 15, 2015 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. Jun 16, 2015 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. Jun 16, 2015 at 11:21
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

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!

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!

3
  • Debian is off-topic here though...
    – Zanna
    Mar 7, 2017 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 Mar 8, 2017 at 2:40
  • That would be great :)
    – Zanna
    Mar 8, 2017 at 5:09
-1

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

1
  • 2
    Please can you state how to install it so others can use it when needed. Jan 3, 2017 at 5:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .