简体   繁体   English

Python Pip 未将 package 安装到虚拟环境 Visual Studio for Mac 中的正确目录中 - “未解决的导入”

[英]Python Pip not installing package into the correct directory in virtual environment Visual Studio for Mac - “unresolved import”

EDIT: See WORKAROUND in reply - if you get "unresolved import" on a package you have installed this might be the reason.编辑:请参阅WORKAROUND回复 - 如果您在 package 上获得“未解决的导入”,则您已安装这可能是原因。

Even though VScode settings are set to use the venv interpreter, and the virtual environment is activated, when using pip or pip3 to install a package in the VSCode terminal, packages are installed into the default python directory.即使 VScode 设置为使用 venv 解释器,并且激活了虚拟环境,当使用 pip 或 pip3 在 VSCode 终端中安装 package 时,软件包安装到默认的 Z23EEEB4347BDD275DZFCB6 目录中。

eg例如

(.venv) person@MacBook-Pro my-code-lives-here % pip3 install python-dotenv

results after trying it twice so you can see the install path:尝试两次后的结果,因此您可以看到安装路径:

Requirement already satisfied: python-dotenv in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (0.15.0)

VS code settings.json: VS 代码设置。json:

"python.pythonPath": ".venv/bin/python3",

Same command was working last week as I have other packages installed.上周,由于我安装了其他软件包,相同的命令正在运行。

WORKAROUND解决方法

use pip's --target arg to specify the site-packages dir of the virutal environment:使用 pip 的 --target 参数来指定虚拟环境的站点包目录:

eg例如

pip3 install --target=/<path-to-code-folder>/.venv/lib/python3.8/site-packages python-dotenv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM