[英]Error When Debugging Django project with ImageFields in Visual Studio Code
I spent so long solving this problem I wanted to post it in case it helps others.我花了很长时间解决这个问题,我想发布它以防它帮助其他人。
I have a django project in Visual Studio Code and I configured a virtual environment for the project.我在 Visual Studio Code 中有一个 django 项目,我为该项目配置了一个虚拟环境。 I would run the project in the Integrated Terminal using manage.py runserver
after activating my virtual environment and that worked.在激活我的虚拟环境之后,我将使用manage.py runserver
在集成终端中运行该项目并且该项目有效。 I created a debug configuration with the default launch.json for django projects.我为 django 项目创建了一个带有默认启动的调试配置。json。 Running the debugger, I got this error:运行调试器,我得到了这个错误:
(fields.E210) Cannot use ImageField because Pillow is not installed.HINT: Get Pillow at https://pypi.org/project/Pillow/ or run command "python -m pip install Pillow".
Pillow was installed in the virtual environment as well as my global python installation. Pillow 安装在虚拟环境以及我的全局 python 安装中。
Note: I'm running Windows 10, python 3.6 and Django 2.2.注意:我正在运行 Windows 10、python 3.6 和 Django 2.2。
I do not know exactly why, but I changed the launch.json to use my global python installation and it now runs.我不知道为什么,但我更改了 launch.json 以使用我的全局 python 安装,它现在可以运行了。 I noticed that running the debugger activates the virtual environment anyway, so this does not seem to be a problem.我注意到运行调试器无论如何都会激活虚拟环境,所以这似乎不是问题。 Here is the launch.json that worked for me:这是对我有用的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: Django",
"pythonPath": "C:\\Users\\<userName>\\AppData\\Local\\Programs\\Python\\Python36\\python.exe",
"type": "python",
"request": "launch",
"program": "manage.py",
"console": "integratedTerminal",
"args": [
"runserver"
],
"django": true
},
]
}
The only change that I really think matters is the pythonPath, everything else I would leave as whatever defaults VS Code sets.我真正认为重要的唯一更改是 pythonPath,我将保留所有其他默认值 VS Code 集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.