python - 无法在同一目录 Visual Studio Code 中找到/导入 .py 文件
问题描述
我一直在互联网上,花了几个小时试图解决这个问题。这可能是一件非常简单的事情,所以请让我放松一下。这是我第一次使用 Visual Studio Code。我已经尝试过以下链接中提供的解决方案:
- VS Code - pylinter 找不到模块
- python模块的vscode导入错误
- 无法让 VSCode/Python 调试器找到我的项目模块
- https://code.visualstudio.com/docs/python/environments
我正在尝试运行 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/”
解决方案
推荐阅读
- linux-kernel - Silabs Si5340:如何为其中一个芯片输出定义时钟
- ios - 去抖属性包装器
- java - Springboot 关闭钩子不适用于 Windows TaskKill
- linux - 删除空行并使用 bash 和 sed 插入多行 - 在匹配前删除单个空行
- django - Django Model FileField 存储使用类取决于设置
- sql - 从两个不同的表sql创建表
- java - Webfilter Java RequestDispatcher 在调试器控制台中提供站点内容,而不是重定向到
- python - 在 Python 中使用套接字 - f-strings:无效的语法
- java - 有没有更好的方法来使用 kafka 实现多租户?
- tinymce - 带有 TinyMCE 内联的可排序 div