visual-studio-code - “未解决的导入”-错误:在 VSCode 中包括代码完成和 pylint 的路径
问题描述
为了有代码完成和功能 linting,我希望 VSCode 包含一个特定的路径。
https://code.visualstudio.com/docs/python/environments#_environment-variable-definitions-file
我创建了一个测试环境
$ pwd
==> /Users/stephan/saitc/test_ws
$ ls -a
==> . .env tst_pckg
==> .. __init__.py
==> .DS_Store testing.code-workspace
$ cat .env
==> PYTHONPATH="/Users/stephan/saitc"
$ ls tst_pckg/
==> CONST.py __init__.py testing.py
$ cat tst_pckg/CONST.py
==> # -*- coding: utf-8 -*-
==>
==> TEST_CONSTANT = "Test constant's value"
$ cat tst_pckg/testing.py
==> # -*- coding: utf-8 -*-
==>
==> from test_ws.tst_pckg.CONST import TEST_CONSTANT
设置“python.envFile”设置为“${workspaceFolder}/.env”
有了这个设置,我希望 VSCode 知道包“test_ws”,但输入以下行:
from test_ws.tst_pckg.CONST import TEST_CONSTANT
在文件“testing.py”中给出了我没有合理的代码完成并且“test_ws.tst_pckg.CONST”无法解决(VSCode ui 中的“未解析导入”-错误)。
我在 macos 上使用 Anaconda 和它附带的 Visual Studio Code 1.30.1。难道我必须从目录“/Users/stephan/saitc/test_ws”启动visual studio代码吗?(如果有怎么办?)
每次启动 Visual Studio Code 时,都会询问我是否要启动 pylint 扩展。我怎样才能永久打开它?(Python›Linting:启用 Pylint,Python›Linting:启用)
谢谢,
斯蒂芬
解决方案
您可以使用配置"python.autoComplete.extraPaths": ["./your-source/folder"]
。
据我了解,env 文件仅在您启动终端等时使用,但不适用于扩展。
推荐阅读
- python - 使用 python 客户端库从日志文件中导出 promethous 指标
- tcl - 如何从 TCL 的测试文件中获取测试文件的名称
- azure-active-directory - 是否可以验证 Azure Active Directory 用户的密码
- reactjs - 如何通过 onPress 将新值传递给 Redux 存储?
- hadoop - 了解 Hadoop 的不同元素
- node.js - 独立 websocket 服务器的 Socket.io“无效帧头”错误
- powershell - 创建 stampfile 文件夹
- powershell - 无法使用 SAS 令牌设置容器权限
- c# - Amazon S3 Api 批量复制到另一个存储桶
- python - 在列表中添加 BeautifulSoup 查找元素