即使激活了虚拟环境,Pip 也会在 pyenv root 中安装软件包
我尝试在之前使用 venv
创建的虚拟环境中使用 pip
安装包。 Python 版本通过 pyenv 进行管理。我不想使用 pyenv 创建虚拟环境。
项目就是这样设置的。在项目空目录中,我添加了包含版本 3.8.2
的 .python-version
。然后我使用 python -m venv .venv 创建了虚拟环境。然后我使用 source .venv/bin/activate
激活了环境。现在命令行以 (.env)
开头。但是,当我尝试使用 pip install some-package
安装某些软件包时,该软件包最终位于 {pyen_home}/versions/3.8.2/lib/python3.8/site-packages
,而不是虚拟环境。
令人恼火的是,我几乎可以肯定我以前确实成功地在虚拟环境中安装了软件包,但现在不行了,所以我看不到我错过了什么。
I try to install a package with pip
in a virtual environement previously created with venv
. The Python version is managed through pyenv
. I don't want to use pyenv
to create the virtual environment.
The project is set up this way. To the project empty directory, I added a .python-version
containing the version 3.8.2
. Then I created my virtual environement using python -m venv .venv
. Then I activated the environement using source .venv/bin/activate
. Now the command line starts with a (.env)
. However, when I try to install some package with pip install some-package
, the package ends up in {pyen_home}/versions/3.8.2/lib/python3.8/site-packages
, instead of the virtual environment.
What's irritating is that I'm almost certain that I did manage to install package in the virtual environment that way before, but not anymore, so I don't see what I'm missing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.python-version
的内容应为.venv
。据我所知,您不应该自己创建此文件。它是在您运行 pyenv local .venv 时生成的。并且 venv 会自动激活。
创建虚拟环境的正确方法是 pyenv virtualenv {python-version} {venv-name}。仔细阅读文档。
Content of your
.python-version
should be.venv
.As far as I know you should not create this file by yourself. It generated when you run
pyenv local .venv
. And venv activates automatically.Also proper way to create virtual environment is
pyenv virtualenv {python-version} {venv-name}
. Read the docs carefully.