pip install -r requirements.txt 在虚拟环境中不起作用

huangapple go评论91阅读模式
英文:

pip install -r requirements.txt is not working in venv

问题

我在使用Python虚拟环境时遇到一个奇怪的问题。如果我激活虚拟环境,然后尝试使用 pip install -r requirements.txt 安装包,这些包会安装到全局Python而不是虚拟环境中。

我在Debian Bookworm上使用Python 3.11.2。

我已经在Google上搜索了2个小时,尝试了包括 https://stackoverflow.com/questions/20952797/pip-installing-in-global-site-packages-instead-of-virtualenv 中的所有方法,但没有帮助。路径设置正确,which pip 给出了虚拟环境pip的路径,没有别名,我创建了配置文件,但什么都没有帮助。

然后,我尝试了不使用 -r requirements.txt 的方式安装一个包,例如 pip install numpy,这样就可以工作,包会安装在虚拟环境中。
那么,为什么pip在使用 -r 参数时无法将包安装到虚拟环境中呢?

英文:

i have this weird problem with python venvs. If i activate the venv and try to install packages via pip install -r requirements.txt the packages are getting installed to the global python and not in the venv.

i am using python 3.11.2 on Debian Bookworm.

I've googled now 2 hours and tried everything including everything in https://stackoverflow.com/questions/20952797/pip-installing-in-global-site-packages-instead-of-virtualenv and nothing helped. The path are correctly set,which pip gives me the path to the venv pip, there are no aliases, i created configfiles but nothing helped.

Then i tried to install a package without the -r requirements.txt e.g. pip install numpy that worked and the packages were installed inside the venv.
So what's the problem of pip not installing packages with the -r parameter to the venv?

答案1

得分: 1

这对我有效:

python -m pip install -r requirements.txt

我认为你的错误是因为pip仍然在引用全局pip。这个命令引用了Python的(虚拟环境Python)pip,而不是全局Python的pip。

英文:

This works for me:

python -m pip install -r requirements.txt

I think you error is occurring because pip is still referring to the global pip. This command refers to python's (the venv python) pip instead of the global python's pip.

huangapple
  • 本文由 发表于 2023年7月14日 03:37:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76682718.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定