-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VSCode运行Python程序提示:ModuleNotFoundError,VSCode未找到导入的自定义的模块,只能手动向sys.path中把项目路径添加,但十分麻烦;Pycharm运行时会自动把项目经路添加至sys.path,开发者无需这般麻烦操作 #19499
Comments
感谢您创建此问题! 然而,由于您没有使用英语,我们很难进行处理。如果可能,请您将此问题描述修改为英文。请您直接编辑此问题,不要提交回复或新问题。 请注意,机器翻译服务通常无法处理用于讨论软件问题所需的技术性语言,所以我们推荐您寻找一位熟悉相关技术的人来协助翻译。 如果您无法做到,没有关系。此问题已经被标记为需要翻译,等待社区成员志愿进行翻译。 Thanks for creating this issue! Unfortunately, as the description is not in English, it's hard for us to work on. If possible, please edit the original issue to be in English. In our experience, automatic translation services are not able to handle the technical language needed to effectively communicate about software issues, so we recommend finding a human translator who is familiar with our technology to help. Otherwise, we have marked this as needing translation and a community member may be able to help out. |
网上同问题解决方案:通过修改项目中.vscode目录下的launch.json添加 "cwd": "${workspaceFolder}",
"env": {
"PYTHONPATH": "${workspaceFolder}"
} 毫无帮助 |
This comment was marked as abuse.
This comment was marked as abuse.
Please look at these images |
This comment was marked as off-topic.
This comment was marked as off-topic.
Check: Try This is not an issue with the extension, it's just an issue in the provided code. |
@PCoeur Can you share the file layout? and what is the path to the file that you are executing? |
@PCoeur 看这个issue的时间是2022-09月的,时间挺久的了,你解决了吗?我已经被这个issue消耗掉了3个小时:sob:,vscode相比于Pycharm易用性对开发者不太友好,我是换vscode才几天的时间。 |
vscode的settings.json中添加以下内容即可:
|
|
|
是的,MacOS... |
vscode的settings.json,项目的settings.json没试过 |
@PCoeur 感谢你的帮助,但是尝尽各种方法还是未解决,我换回Pycharm了,先解决工作的问题了,以后有时间再慢慢研究:smile: |
OK |
谢谢,你提供的方法很有用 |
不客气 |
目前看到的所有方案试了下都无效😭,标记下继续研究了 |
展开说说 |
发现问题了,之前因为没把改配置之前的bash终端关掉,导致代码一直运行在旧的bash终端上,新增的配置没生效,现在把vscode右下角的bash全关了,重新运行就可以了 |
试了一圈让配置项目里边.vscode/lanuch.json的都不行,你这个方法一下就成了,强👍 |
this is true.但是你设置后,需要重新打开项目或者命令行,才能生效。 不过这个是为什么错误呢? |
在项目根目录创建一个.venv就可以解决了,可以实现Pycharm的自动导包效果! |
.venv空隐藏文件?这种方案只针对当前项目有用,其他项目还需要这样搞有点麻烦 |
crtil + shift + p 在当前项目根目录下创建虚拟环境目录.venv |
添加的配置没生效,可以重新加载窗口(Win: ctrl + shift + p快捷键) |
虚拟环境也是可以,前面本人提供的那种解决方案主要解决不创建虚拟环境场景 |
非常感谢, 已经解决了, 之前是每次都要自己手动打全部路径加上 -m, 感觉天都塌了 |
正确的解决方案,需要重新打开新的Terminal 窗口,运行正常 |
Issue Type: Bug
VSCode运行Python程序提示:ModuleNotFoundError
VS Code version: Code 1.69.2 (3b889b090b5ad5793f524b5d1d39fda662b96a2a, 2022-07-18T16:12:52.460Z)
OS version: Windows_NT x64 10.0.19044
Restricted Mode: No
The text was updated successfully, but these errors were encountered: