pyvenv-3.4 returned non-zero exit status 1

Question:

I’m in Kubuntu 14.04 , I want to create a virtualenv with python3.4. I did with python2.7 before in other folder. But when I try:

pyvenv-3.4 venv

I’ve got:

Error: Command '['/home/fmr/projects/ave/venv/bin/python3.4', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

Asked By: kahonmlg

||

Answers:

I got a solution installing python-virtualenv

sudo apt-get install python-virtualenv

and using

virtualenv --python=/usr/bin/python3.4 venv
Answered By: kahonmlg

Pyvenv comes bundled with newer version of python 3 and is supposed to replace virtualenv, so it’s not quite the same thing.

There was some problem with the python 3.4 in the first release of Ubuntu 14.04 that caused this error.

Upgrading the distro solved this issue for me. I guess it probably works with Kubuntu as well.

sudo do-release-upgrade -d # this takes a while, and involves a reboot as well. 
sudo apt-get install python3.4-venv
pyvenv-3.4 venv

Please read the docs for do-release-upgrade before running it. Using the -d flag will upgrade to latest devel release, which might include some unstable software.

You can’t undo do-release-upgrade

Answered By: Håken Lid

Same problem on Linux Mint 17 (which is basically Ubuntu 14.04). Installing python3.4-venv didn’t work, so I created virtualenv without pip and then installed pip manually.

  1. Create virtualenv and activate it

    python3 -m venv --without-pip foo
    source foo/bin/activate
    
  2. Download latest versions of setuptools and pip:

    wget https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.tar.gz#md5=6245d6752e2ef803c365f560f7f2f940
    wget https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz#md5=01026f87978932060cc86c1dc527903e
    
  3. Unpack and install them

    tar xf setuptools-7.0.tar.gz
    tar xf pip-1.5.6.tar.gz
    cd setuptools-7.0
    python setup.py install
    cd ../pip-1.5.6
    python setup.py install
    
Answered By: alexanderlukanin13

The following worked for me on Ubuntu 13.10:

pyvenv-3.4 delme --without-pip
source delme/bin/activate
python -Im ensurepip --upgrade --default-pip
Answered By: Matt R

I had encountered this issue.

To investigate, I executed the same command as pyvenv did, and then I got “locale.Error: unsupported locale setting”.

It finally fixed by configuring “LC_ALL=en_US.UTF-8”.

Answered By: Neron.L

Here is an O/S agnostic solution:

Both the pyvenv and python commands themselves include a --without-pip option that enable you to work around this issue; without resorting to setuptool or other headaches. Taking note of my inline comments below, here’s how to do it, and is very easy to understand:

user$ pyvenv --without-pip ./pyvenv.d          # Create virtual environment this way;
user$ python -m venv --without-pip ./pyvenv.d  # --OR-- this newer way. Both work.

user$ source ./pyvenv.d/bin/activate  # Now activate this new virtual environment.
(pyvenv.d) user$

# Within it, invoke this well-known script to manually install pip(1) into /pyvenv.d:
(pyvenv.d) user$ curl https://bootstrap.pypa.io/get-pip.py | python

(pyvenv.d) user$ deactivate           # Next, reactivate this virtual environment,
user$ source ./pyvenv.d/bin/activate  # which will now include the pip(1) command.
(pyvenv.d) user$

(pyvenv.d) user$ which pip            # Verify that pip(1) is indeed present.
/path/to/pyvenv.d/bin/pip

(pyvenv.d) user$ pip install --upgrade pip # And finally, upgrade pip(1) itself;
(pyvenv.d) user$                           # although it will likely be the
                                           # latest version. And that's it!

I hope this helps. (◠﹏◠)/

Answered By: NYCeyes

Quite similar to @prismalytics.io but for those of you who don’t like running shell scripts from the web. You can, of course, use –no-index –find-links to point to local copies. Any recent pip wheel file will suffice, this just points to the current version on PyPI.

python3 -m venv --without-pip your_venv
source your_venv/bin/activate
curl 'https://pypi.python.org/packages/b6/ac/7015eb97dc749283ffdec1c3a88ddb8ae03b8fad0f0e611408f196358da3/pip-9.0.1-py2.py3-none-any.whl' > pip.whl
python -m zipfile -e pip.whl $VIRTUAL_ENV/lib/python3*/site-packages
python -m pip install --force-reinstall --upgrade pip
Answered By: whatintheworld

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

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

And then create your virtualenv

python3.4 -m venv myVenv
Answered By: Gregory

This worked for me in python 3.6 and OSX

$ python -m venv --without-pip my_dir
$ source my_dir/bin/activate
$ curl https://bootstrap.pypa.io/get-pip.py | python
$ deactivate
$ source my_dir/bin/activate
(my_dir) user$
Answered By: Adarsh V C

On LMDE2 with :

  • Python 3.4.2
  • Debian_version : 8.11

It was the first time I use python on this machine and I encountered this problem:

freezed@machine ~/git/repo % python3 -m venv .venv                            
Error: Command '['/home/freezed/git/repo/.venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
zsh: exit 1     python3 -m venv .venv

I solved this problem with :

sudo apt-get install python3.4-venv

Answered By: freezed

I was also facing the same issue.

[niraj@abc ~]$/python/v3.7.0/bin/python3 -m venv avd
Error: Command '['/home/niraj/avd/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

After adding libffi3.3 on my LD_LIBRARY_PATH it works

setenv LD_LIBRARY_PATH /libffi/v3.3/lib64

Answered By: niraj pandey

I had below Issues with psutil installation in Ubuntu 16.04 :

Building wheel for psutil (setup.py) … error

These are my steps which worked:

check your Python version. (My Python version is 3.7)

then done this below addtitional step:

sudo apt-get install python3.7-dev

then

pip install psutil 

source ./my_venv_dir/bin/activate

pip install --upgrade pip
Answered By: Vizag

For Windows User coming to this post, follow these steps:-

You can make sure that pip is up-to-date by running:
python -m pip install --upgrade pip

Install virtualenv by running:
python -m pip install --user virtualenv

Finally create environment using
python -m virtualenv <your env name>

Answered By: Ashutosh Gupta

This is my solution for the error:

$ python3.6 -m venv venv

Failing command: [‘/venv/bin/python3.6’, ‘-Im’, ‘ensurepip’, ‘–upgrade’, ‘–default-pip’]

Solution:

$ rm -rf venv
$ apt install python3.6-venv
$ python3.6 -m venv venv
Answered By: mascai

Just run the command:

$ apt-get install python3-venv

and then create your virtual environment by running:

$ python3.6 -m venv
Answered By: Hayat Khan

This is a wild edgecase, but if you have a file called csv.py in your work directory when you create the virtual environment with python3.9, ensurepip will fail.

Delete or rename the file and it should succeed

    $ touch csv.py
    $ python3.9 -m venv venv
    Error: Command '['/test/venv/bin/python3.9', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
    $ rm -rf venv/
    $ rm csv.py 
    $ python3.9 -m venv venv
    $ ls venv/
    bin/        include/    lib/        pyvenv.cfg

Answered By: jamestufen

I encountered a very similar error caused by a very different issue. We use SLURM as the workload manager on a computer cluster. As such, we ‘helpfully’ set TMPDIR to ensure users don’t fill up the local file systems on the compute nodes.

In my case it boils down to an issue with venv:__init__.py:_setup_pip() spawning a separate subprocess. The error initially given is deceptive because the real error is lost when calling subprocess.

After encountering the error, and keeping the state of the failed virtual environment the same, you can be clever and run the failed command (i.e. the subprocess) in the debugger. In my case it was

python -m pdb -m ensurepip --upgrade --default-pip

From there you can step through the debugger and figure out what the real issue was. In my case it boils down to something in pip/_internal/utils/temp_dir.py (from the wheel file downloaded during install attempt) trying to create an adjacent directory, and it not quite working with our setting of TMPDIR. The solution was to set export TMPDIR=/tmp and it worked just fine.

Obviously, there is likely a whole subset of problems with very similar errors to that posted by @kahonmlg. Properly debugging the spawned process is the key to solving those problems. In my case the solution was just to set TMPDIR, but obviously your mileage may vary.

None of the solutions above worked. It came down to a python file within my directory named calendar.py. My guess is that there’s probably some conflict happening as the venv process thinks my calendar.py file is Python’s official calendar module.

Anyways, after renaming the file, the issue was resolved.

Answered By: Scratch'N'Purr

Windows + Studio Code

I had the same problem running an Ubuntu from Windows (WSL) directly from VS Code (i.e. Ubuntu installed on WSL and Remote Developper extension to execute Ubuntu terminal directly from VS Code).

The solution to use –without-pip as offered by many here was also triggering an error.

It’s link to the fact that PATH did not referenced pip installation folder. I had to manualy set it in my WSL environment : export PATH=$PATH:/path/to/my/program
The PATH to pip should be something like : /home/[linuxuser]/.local/bin where [linuxuser] is your account name

You can check you PATH in Linux with the following command : echo $PATH

Answered By: samuel guedon
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.