Error: Command '['/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

created at 09-09-2021 views: 368

method 1

Under ubuntu16.04, using the python3.5 that comes with the system to create a virtual environment is normal, but when I install python3.6, the installation of the virtual environment will report an error. The following are the errors encountered and the solutions.

After installing pyhton3.6, create a virtual environment with python3.6

 python3 -m venv myenv

The following error will be reported:

Error: Command '['/root/myenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

Try to create a virtual environment with the virtualenv command again, and select python3.6

virtualenv -p python3.6 myenv01

The following error will be reported:

Traceback (most recent call last):   File "/usr/lib/python3/dist-packages/virtualenv.py", line 22, in <module>     import zlib ModuleNotFoundError: No module named 'zlib'

At this time, it is found that zlib is missing, so zlib must be installed

sudo apt-get install zlib1g-dev

After the installation is successful, you need to reinstall python3.6, that is, execute the installation statement in the python3.6 directory downloaded from the official website:

./configure

make

sudo make install

Create the virtual environment again at this time

python3 -m venv myenv

No error will be reported, successfully created!

Method 2:

​ Using venv to create a virtual environment fails, and the error is reported as above.

python -m venv ll_venv

environment:

  • Ubantu16.04
  • ​three python versions: python2.7, python3.5, python3.6
  • python defaults to python3.6

solution

​ Lack of dependent packages, just install python3.6-venv.

sudo apt-get install python3.6-venv

summary

​It should be that each python3 version has its own venv. The default installation of python3-venv should be python3.5-venv, but the default python3 of the system is python3.6. That can only be interpreted as python3-venv is interpreted remotely and interpreted as the minimum version of python3 installed on the system. Therefore, to specify the python3 version of venv in a system with multiple python3 versions, it is best to manually specify the python3 version to install.

created at:09-09-2021
edited at: 09-09-2021: