我有以下 settings.json
{
"python.pythonPath": "C:\\Users\\james\\OneDrive\\Programming Projects\\Python\\webscraper\\Scripts\\python.exe",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "\\Scripts\\pylint.exe"
}
以及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 (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
当我转到我想调试并选择我的Python: Current File (Integrated Terminal)
调试器的文件时,它会显示我的断点并显示以下内容:
另一方面,如果我设置了一个新的解释器,例如:
"C:\\Users\\james\\AppData\\Local\\Programs\\Python\\Python39-32\\python.exe"
它将运行调试器,但同时,它不会考虑我的 venv,因此会引发有关缺少模块的错误(应该如此)。
你知道我可能哪里出错了吗?
这里有几点要提:
The environment should not have your files inside it, it's supposed to be something you use and throw away at a whim. Place project files outside of the environment you create. I laid mine out as a folder called "env" that I created using:
py -m venv env
and then after it was created, I activated it with
env/Scripts/activate
Second of all, don't forget to ensure your vscode folder is in that root folder, here are my settings for my configuration that ended up working.
This seemed to be really important:
"python.linting.pylintArgs": [
"--init-hook",
"import sys; sys.path.append('C:\\Users\\james\\OneDrive\\Programming Projects\\Python')"
],
And just in case it wasn't clear how my folder structure now looks like. the main.py
, logic
, models
and services
folders are my own code. The env
folder is the environment created with venv
:
Just an extra bonus, don't forget to create a requirements.txt that stores libraries you use in your project
然后,您可以使用以下方法安装:
py -m pip install -r requirements.txt
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句