繁体   English   中英

在 venv 中导入已安装的模块时出现 ModuleNotFoundError

[英]ModuleNotFoundError when importing installed module in venv

我在 Visual Studio Code 中使用venv在虚拟环境中安装了一个库,然后将其导入到 Python 文件中。 但是,当我运行该文件时,我得到一个 ModuleNotFoundError。

尝试的步骤和检查:

  • 我没有安装多个版本的 Python。
  • 我在安装模块和运行文件之前激活了 venv。
  • VS Code 说它正在使用 \venv\scripts 中的 Python 可执行文件。
  • 该模块实际上位于venv\Lib\site-packages中。
  • 我在 venv 内外运行最新版本的 pip。
  • 我重新启动了 VS Code。

奇事:

  • 从内置终端运行文件而不是引发错误。
  • which python in Bash returns /c/Users/Lyndon/Documents/VS Code/seatmap_parser/\Users\Lyndon\Documents\VS Code\seatmap_parser\venv/Scripts/python when it should presumably return C:\Users\Lyndon\Documents\VS Code\seatmap_parser\venv\Scripts\python
  • 将设置"python.pythonPath": "${workspaceRoot}/venv/Scripts/python"添加到工作区settings.json会引发此错误: The Python path in your debug configuration is invalid.
  • 如果我停用 venv,全局安装模块,然后重新激活 venv,该文件现在可以正常工作,这让我认为可能以某种方式运行了错误的 Python 可执行文件。

我随时准备应要求检查任何遗漏的细节。 为什么它不起作用?

如果你想得到 OUTPUT 只需在指定文件中单击run ,那么你必须对 go 用户设置。 在“python”键后的"code-runner.executorMap ”字典中输入您的 python 路径。 如果未指定,只需键入code-runner.executorMap ,它将为您生成该字典。

暂无
暂无

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

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