如果使用Python
命令创建pyvenv
虚拟环境时遇到以下错误:
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
...然后,答案(如下)提供了一种解决它的简单方法,而不是求助于
setuptools
及其相关的杂技。 最佳答案
这是一种与操作系统无关的方法 ...pyvenv
和python
命令本身都包含--without-pip
选项,使您可以解决此问题。无需诉诸setuptool
或其他麻烦。在下面记下我的inline comments
,这里是操作方法,非常容易理解:
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!
我希望这有帮助。\(◠﹏◠)/
关于python - pyvenv返回非零退出状态1(在安装pip阶段期间),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41430706/