简体   繁体   English

导入 [Module] 无法从源解决PylancereportMissingModuleSource

[英]Import [Module] could not be resolved from sourcePylancereportMissingModuleSource

I'm trying to import pymysql to my python script in VSCode but am getting the following error我正在尝试在 VSCode 中将 pymysql 导入我的 python 脚本,但出现以下错误

Import "pymysql" could not be resolved from sourcePylancereportMissingModuleSource

I installed the module with pip the same way I have with all other modules such as Pandas, which works fine我使用 pip 安装模块的方式与安装所有其他模块(例如 Pandas)的方式相同,效果很好

Here's the import line for reference这是供参考的导入行

import pymysql

Any quick fixes or explanations of what is going on would be appreciated, thanks任何快速修复或对正在发生的事情的解释将不胜感激,谢谢

You need to add your current working directory to the Python search path.您需要将当前工作目录添加到 Python 搜索路径。 This can be done with an environment variable:这可以通过环境变量来完成:

export PYTHONPATH=.

There is a similar question here: Import "flask" could not be resolved from sourcePylancereportMissingModuleSource这里有一个类似的问题: Import "flask" could not be resolve from sourcePylancereportMissingModuleSource

Run pip show pymysql to check if module is installed in \current selected interpreter\lib\site-packages :运行pip show pymysql检查模块是否安装在\current selected interpreter\lib\site-packages

在此处输入图像描述

If not, please reinstall it to current used environment.如果没有,请将其重新安装到当前使用的环境中。 If it is, open Command Palette(Ctrl+Shift+P) and choose Reload Window , the warning should go away.如果是,请打开Command Palette(Ctrl+Shift+P)并选择Reload Window ,警告应该会消失。

  1. Check for the current Python Interpreter VSCode is using Ctrl+P .检查当前的 Python Interpreter VSCode 是否正在使用Ctrl+P

  2. Add your virtual environment PATH where your module is installed in 'C:\Users\<username>\.virtualenvs\<virtualenvname>\Scripts\python' .'C:\Users\<username>\.virtualenvs\<virtualenvname>\Scripts\python'中添加安装模块的虚拟环境 PATH。

运行 python3 -m pip install pymysql 如果你继续遇到同样的问题,请从解释器部分将你的 python 解释器从全局更改为 windows 存储

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

相关问题 无法从 sourcePylancereportMissingModuleSource 解析导入“urllib3” - Import "urllib3" could not be resolved from sourcePylancereportMissingModuleSource 无法从 sourcePylancereportMissingModuleSource 解析导入“pandas” - Import “pandas” could not be resolved from sourcePylancereportMissingModuleSource 无法从 sourcePylancereportMissingModuleSource 解析导入“flask” - Import "flask" could not be resolved from sourcePylancereportMissingModuleSource 导入模块无法解析 - Import module could not be resolved 键盘模块(无法从源 Pylance 解析导入“键盘”(reportMissingModuleSource)) - Keyboard module (Import "keyboard" could not be resolved from source Pylance (reportMissingModuleSource)) 在 pyright 中修复“无法解析导入 [模块]” - Fixing 'Import [module] could not be resolved' in pyright 我的自定义模块的导入无法解决 - Import of my custom module could not be resolved 无法解析导入 [Module] (PylancereportMissingImports),模块位于同一文件夹/目录中 - Import [Module] could not be resolved (PylancereportMissingImports), with module in the same folder/directory 无法从 sourcePylance 解析导入“jsonschema” - Import "jsonschema" could not be resolved from sourcePylance 无法从源解析导入“bs4” - Import "bs4" could not be resolved from source
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM