简体   繁体   English

如何使用 VScode 在 python 中修复导入错误:No module named...

[英]how to fix Import Error: No module named... in python with VScode

I am trying to import a module into vsCode.我正在尝试将模块导入 vsCode。 I have attached some photos of my current set up right.我附上了一些我当前设置的照片。 Things to note:注意事项:

  • I am running the project in a virtual environment我在虚拟环境中运行项目
  • My interpreter is set up to use this virtual env我的解释器设置为使用这个虚拟环境
  • I have my python:path set to run through the environment我将 python:path 设置为在环境中运行
  • I have the required modules in env/lib/ folder.我在 env/lib/ 文件夹中有所需的模块。

在此处输入图片说明 在此处输入图片说明

This results in an import error even though I believe I have taken the correct steps in setting up my python project in vscode.这会导致导入错误,即使我相信我已经采取了正确的步骤在 vscode 中设置我的 python 项目。 If someone has experienced anything similar can you please provide input on how to solve this issue?如果有人遇到过类似的事情,您能否提供有关如何解决此问题的意见?

Install code-runner and place code below in settings.json folder安装 code-runner 并将代码放在 settings.json 文件夹下面

    "code-runner.executorMap": {
        "python": "python3 -u",
    }

"python": "(the python version with modules) -u", "python": "(带有模块的 python 版本)-u",

My guess is you never installed the requests module.我的猜测是您从未安装过 requests 模块。

You need to do你需要做

pip install requests

for Python to find it.让 Python 找到它。

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

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