pyvenv-3.4 returned non-zero exit status 1

PythonUnixPython 3.xVirtualenv

Python Problem Overview


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

Python Solutions


Solution 1 - Python

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

Solution 2 - Python

I got a solution installing python-virtualenv

sudo apt-get install python-virtualenv

and using

virtualenv --python=/usr/bin/python3.4 venv

Solution 3 - Python

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. (◠﹏◠)/

Solution 4 - Python

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

Solution 5 - Python

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
    

Solution 6 - Python

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

Solution 7 - Python

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$

Solution 8 - Python

Just run the command:

$ apt-get install python3-venv

and then create your virtual environment by running:

$ python3.6 -m venv

Solution 9 - Python

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

Solution 10 - Python

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>

Solution 11 - Python

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

Solution 12 - Python

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

Solution 13 - Python

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".

Solution 14 - Python

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

Solution 15 - Python

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

Solution 16 - Python

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

Solution 17 - Python

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.

Solution 18 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkahonmlgView Question on Stackoverflow
Solution 1 - PythonGregoryView Answer on Stackoverflow
Solution 2 - PythonkahonmlgView Answer on Stackoverflow
Solution 3 - PythonNYCeyesView Answer on Stackoverflow
Solution 4 - PythonmascaiView Answer on Stackoverflow
Solution 5 - Pythonalexanderlukanin13View Answer on Stackoverflow
Solution 6 - PythonHåken LidView Answer on Stackoverflow
Solution 7 - PythonAdarsh V CView Answer on Stackoverflow
Solution 8 - PythonHayat KhanView Answer on Stackoverflow
Solution 9 - PythonfreezedView Answer on Stackoverflow
Solution 10 - PythonAshutosh GuptaView Answer on Stackoverflow
Solution 11 - PythonwhatintheworldView Answer on Stackoverflow
Solution 12 - PythonjamestufenView Answer on Stackoverflow
Solution 13 - PythonNeron.LView Answer on Stackoverflow
Solution 14 - PythonMatt RView Answer on Stackoverflow
Solution 15 - Pythonniraj pandeyView Answer on Stackoverflow
Solution 16 - PythonVizagView Answer on Stackoverflow
Solution 17 - Pythonirritable_phd_syndromeView Answer on Stackoverflow
Solution 18 - PythonScratch'N'PurrView Answer on Stackoverflow