Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyvenv returns non-zero exit status 1 (during the installation of pip stage)

If you should ever encounter the following error when creating a Python virtual environment using the pyvenv command:

user$ pyvenv my_venv_dir
Error: Command '['/home/user/my_venv_dir/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

... then the answer (below) provides a simple way to work around it, without resorting to setuptools and it's related acrobatics.

like image 973
NYCeyes Avatar asked Jan 02 '17 17:01

NYCeyes


People also ask

Can not perform a -- user install user site packages are not visible in this Virtualenv?

If this command returns Can not perform a '--user' install. User site-packages are not visible in this virtualenv. then you are already in a Python virtual environment. You will need to deactivate this environment or contact your system administrator to install virtualenv for you in this environment.

What is virtual environment for Python?

A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them. This is one of the most important tools that most of the Python developers use.


1 Answers

Here's an approach that is fairly O/S agnostic...

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 already.
# And that's it!

I hope this helps. \(◠﹏◠)/

like image 140
NYCeyes Avatar answered Nov 15 '22 04:11

NYCeyes