【发布时间】:2020-12-07 01:51:55
【问题描述】:
我一直在互联网上,花了几个小时试图解决这个问题。这可能是一件非常简单的事情,所以请让我放松一下。这是我第一次使用 Visual Studio Code。我已经尝试过以下链接中提供的解决方案:
- VS Code - pylinter cannot find module
- vscode import error for python module
- Can't get VSCode/Python debugger to find my project modules
- https://code.visualstudio.com/docs/python/environments
My folder structure looks like this:
我正在尝试运行 urls.py 文件,该文件尝试使用 -
导入视图文件from . import views
但我收到以下错误:
Traceback(最近一次调用最后一次): 文件“c:/Users/abc/projects/telusko/calc/urls.py”,第 7 行,在 从 。导入视图 ImportError:无法导入名称“视图”
我已经尝试了所有可能的组合,目前我的 launch.json 文件如下所示:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}],
"env": {"PYTHONPATH": "c:/Users/abc/projects/telusko/"},
"python.pythonPath": "c:/Users/abc/Envs/test/Scripts/python.exe"
}
我正在使用虚拟环境来运行这个项目,环境位于 - “c:/Users/abc/projects/telusko/test/”
而我的项目目录位于-
“c:/Users/abc/projects/telusko/”
【问题讨论】:
-
PYTHONPATH不应指向可执行文件,而应指向项目的根目录,然后(用冒号分隔)其他要查找的位置。 -
试过了,不行。更新了上述代码以反映最新版本的 launch.json 文件。
-
这可能是VS spacevim.org的替代品
-
嗨@Armagon,你能详细说明一下吗?
-
这有助于解决您的问题吗? stackoverflow.com/questions/9252543/…
标签: python python-3.x django visual-studio visual-studio-code