gpt4 book ai didi

python - pyvenv 返回非零退出状态 1(在安装 pip 阶段期间)

转载 作者:太空宇宙 更新时间:2023-11-03 13:35:02 25 4
gpt4 key购买 nike

如果您在使用 pyvenv 命令创建 Python 虚拟环境时遇到以下错误:

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 及其相关的技巧。

最佳答案

这是一种与 O/S 完全无关的方法...

pyvenvpython 命令本身都包含一个 --without-pip 选项,可以让您解决这个问题;无需求助于 setuptool 或其他令人头疼的问题。记下我在下面的内联注释,这里是如何做的,而且很容易理解:

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!

希望对您有所帮助。\(◠﹏◠)/

关于python - pyvenv 返回非零退出状态 1(在安装 pip 阶段期间),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41430706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com