41

When trying to create a virtulenv using venv with python 3 on ubuntu it isn’t creating an activate script. It conitunally exits with an error 1.

Following docs and other posts on SO such as https://stackoverflow.com/a/19848770

I have tried creating it 2 different ways.

sayth@sayth-TravelMate-5740G:~/scripts$ python3 -m venv test4
Error: Command '['/home/sayth/scripts/test4/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
sayth@sayth-TravelMate-5740G:~/scripts$ source test4/bin/activate
bash: test4/bin/activate: No such file or directory
sayth@sayth-TravelMate-5740G:~/scripts$ ls test4/bin/
python  python3

or

sayth@sayth-TravelMate-5740G:~/scripts$ pyvenv-3.4 test5
Error: Command '['/home/sayth/scripts/test5/bin/python3.4', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
sayth@sayth-TravelMate-5740G:~/scripts$ ls test5/bin/
python  python3  python3.4

How can I get it to fully create a venv?

If I do it as below with stil no success unsure what the issue is?

sayth@sayth-TravelMate-5740G:~/scripts$ python3 -Im venv panda3
Error: Command '['/home/sayth/scripts/panda3/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
sayth@sayth-TravelMate-5740G:~/scripts$ python3 -m venv panda4
Error: Command '['/home/sayth/scripts/panda4/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
Community
  • 1
  • 1
sayth
  • 6,696
  • 12
  • 58
  • 100

4 Answers4

109

Looks like you are using Ubuntu 14.04. It was shipped with a broken pyvenv. There is a simple work around to create venv using Python 3

1. Create venv without pip

python3 -m venv --without-pip test4

or

pyvenv-3.4 --without-pip test4

2. Get pip in your env

source test4/bin/activate
curl https://bootstrap.pypa.io/get-pip.py | python
deactivate
source test4/bin/activate

or

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

Source: HackerNews, AskUbuntu

Community
  • 1
  • 1
Chillar Anand
  • 27,936
  • 9
  • 119
  • 136
  • Thanks reading log also workaround is another work around is to do: sudo apt-get install python-virtualenv virtualenv myvenv -p python3 – sayth Oct 11 '14 at 12:30
  • Very weird. I'm on 14.04 & Python3, and had no issue with my `pyvenv`. – Eduard Luca Oct 17 '14 at 14:52
  • you have 14.04 or 14.04.1? – Chillar Anand Oct 17 '14 at 14:55
  • I'm on macOS and I'm getting the same error, I was wondering if there was a solution rather than a work around. – Ahmed Eid Nov 28 '17 at 01:15
  • Yes, what about 16.04 ? Was it shipped with a broken pyvenv ? Yet I remember being able to create some without issues a few weeks ago – Alice Antoine Sep 02 '18 at 10:41
  • 2
    I had to use this work around with Ubuntu 20.04. – remcycles Jul 28 '21 at 18:09
  • 1
    @remcycles Also had this problem on a relatively fresh 20.04 install (WSL if that matters) and the issue was `pip` wasn't installed. After installing with `sudo apt-get install python3-pip` and recreating the virtual environment, all the expected files were there. – tomocafe Jul 06 '22 at 15:04
14

Anaconda involucred.

If you are using Anaconda or Miniconda this solution may help:

Conda manages python itself as a package, so that conda update python is possible, in contrast to pip, which only manages Python packages. Conda is available in Anaconda and Miniconda (an easy-to-install download with just Python and conda).

So, this command would help:

conda update python

very disturbing for me but well, hands to the keyboard in a terminal window: (click here, see the picture)

Thanks for your attention, have a nice day!

Jimmy Olano
  • 149
  • 1
  • 5
  • 1
    Good catch, I had forgotten I had installed anaconda the other day. This fixed my python3 creating virtual environments. – FishStix Dec 01 '17 at 17:25
  • This helped me create "vanilla" virtual envs while using Anaconda as my primary python install. Thanks! – Aaron Mar 01 '18 at 00:54
13

The command:

python3 -m virtualenv env

works for me, whereas:

python3 -m venv env

does not.

Rory
  • 189
  • 1
  • 6
7

This worked for me:

python3 -m venv --without-pip test4

Once I typed that in the terminal, the "test4" venv was created. And the 'activate' script was also created in the 'bin' directory.

To anyone using python3, having trouble with this, just substitute the name of the directory you want to create for "test4" (or rename it later).

That should do it.

Bugs
  • 4,491
  • 9
  • 32
  • 41
KenBlend
  • 81
  • 1
  • 3