pyvenv-3.4 returned non-zero exit status 1
Asked Answered
P

20

185

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

Primo answered 9/6, 2014 at 15:6 Comment(2)
A solution is given here: askubuntu.com/questions/488529/…Mannerism
I had this issue, and it turned out that I needed to install libffi-devel before configuring, making, and installing Python3. After doing that, my pip woes were solved.Zerlina
P
81

I got a solution installing python-virtualenv

sudo apt-get install python-virtualenv

and using

virtualenv --python=/usr/bin/python3.4 venv
Primo answered 9/6, 2014 at 15:18 Comment(4)
Why do you have to provide the full path?Deify
@ThePassenger: At least in my case, you don't.Campuzano
E: Package 'python-virtualenv' has no installation candidateAlithea
Note that virtualenv is not the same as venvCircosta
M
280

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
Matthiew answered 14/8, 2017 at 10:27 Comment(8)
E: Couldn't find any package by regex 'python3.7-venv' While installingCosmetic
@indrajitnarvekar, python3.7 is not yet in default repositories. You can use deadsnakes PPA. See this question for details: askubuntu.com/questions/865554/…. Python 3.7 is available in this PPA as well, so the answer applies to it too.Bunns
This is the best solution! Not installating a different product (virtualenv vs. venv) or installing by circumventing APT.Stereography
This answer is also works for Python3.8 -- just install python3.8-dev and python3.8-venvStriation
Python 3.9 works as well: apt install python3.9-dev python3.9-venv.Teodora
This works for Python 3.10, no issues apt-get install python3.10-dev python3.10-venvLongs
For anyone wondering what is the -dev version: Header files and a static library for PythonAbbatial
Livesaving tbh.Rafaello
P
81

I got a solution installing python-virtualenv

sudo apt-get install python-virtualenv

and using

virtualenv --python=/usr/bin/python3.4 venv
Primo answered 9/6, 2014 at 15:18 Comment(4)
Why do you have to provide the full path?Deify
@ThePassenger: At least in my case, you don't.Campuzano
E: Package 'python-virtualenv' has no installation candidateAlithea
Note that virtualenv is not the same as venvCircosta
M
78

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
Martel answered 16/6, 2020 at 19:9 Comment(3)
installing python venv fixed the issue for me. tnxHydrometer
This fix the issue on 3.9 as well. Thanks.Towroy
Did not fix 3.10Befog
H
68

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

Hamelin answered 2/1, 2017 at 17:9 Comment(1)
Does not work on Debian Wheezy with Python 3.3 installed manually: venv: error: unrecognized arguments: --without-pipBarraza
C
33

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
    
Childers answered 4/12, 2014 at 16:6 Comment(1)
Thanks for this solution. Worked for me. I installed pip and setuptools together with such command: wget bootstrap.pypa.io/get-pip.py -O - | pythonChelicera
R
16

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>

Relentless answered 8/5, 2020 at 11:36 Comment(4)
I ran into this problem on sles15sp2 with python 3.6.12 This workaround was effective for me.Sinusitis
I'm using Windows and faced this error too. What was causing the issue for me was a Python file named "copy.py" in the root of my Python project. Renaming the file to something unique fixed the issue for me.Lallygag
CAUTION This is for python 2.7. Activate your venv and check version afterwards. you may be surprised by an older pythonAlithea
Perfect! For completeness I'd add to use the following to activate the virtual environment: <venv_path>\Scripts\activateScevor
N
13

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

Nannana answered 8/9, 2014 at 14:13 Comment(4)
Be aware that upgrading the distro to the devel version will also update other software. So there might be side effects of this solution.Scandalmonger
Good to mention that. I'm already running Ubuntu 14.10 but installing python3.4-venv fixed the problem in particular.Daye
For me, the sudo apt-get install python3.4-venv part was sufficient as well.Derwon
Upgrading your distribution is major overkill here.Blitzkrieg
H
12

Just run the command:

$ apt-get install python3-venv

and then create your virtual environment by running:

$ python3.6 -m venv
Hopkins answered 22/8, 2020 at 19:17 Comment(1)
For ubuntu20.04 & python3.10 -> sudo apt install python3.10-venvOlszewski
A
9

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$
Amparoampelopsis answered 28/9, 2017 at 5:28 Comment(0)
H
9

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

Halley answered 25/7, 2018 at 13:30 Comment(0)
C
6

This worked for me

sudo apt install python3.11
sudo apt install python3.11-dev python3.11-venv python3.11-distutils python3.11-gdbm python3.11-tk python3.11-lib2to3
python -m venv folder
Convolution answered 6/6, 2023 at 6:20 Comment(0)
S
3

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

Semite answered 23/6, 2021 at 16:13 Comment(1)
how do we know which file is causing this ?Barbule
F
2

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
Forepaw answered 24/5, 2017 at 17:49 Comment(0)
C
1

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

Centroclinal answered 22/12, 2016 at 3:35 Comment(0)
O
1

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

Ostensory answered 9/8, 2022 at 19:29 Comment(0)
A
0

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
Albany answered 5/2, 2015 at 15:53 Comment(1)
It says /tmp/delme/bin/python: No module named ensurepipCymric
A
0

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

Anthia answered 11/12, 2018 at 3:45 Comment(1)
where is LD_LIBRARY?Alithea
P
0

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
Proctor answered 15/1, 2020 at 12:52 Comment(0)
C
0

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.

Consanguinity answered 11/1, 2022 at 4:14 Comment(0)
P
0

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.

Per answered 12/1, 2022 at 12:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.