【问题标题】:Error When Debugging Django project with ImageFields in Visual Studio Code在 Visual Studio Code 中使用 ImageFields 调试 Django 项目时出错
【发布时间】:2020-04-06 23:33:41
【问题描述】:

我花了很长时间解决这个问题,我想发布它以防它帮助其他人。

我在 Visual Studio Code 中有一个 django 项目,我为该项目配置了一个虚拟环境。在激活我的虚拟环境之后,我会在集成终端中使用manage.py runserver 运行该项目,这很有效。我使用 django 项目的默认 launch.json 创建了一个调试配置。运行调试器,我得到了这个错误:

(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 安装在虚拟环境以及我的全局 python 安装中。

【问题讨论】:

    标签: python django visual-studio-code


    【解决方案1】:

    注意:我正在运行 Windows 10、python 3.6 和 Django 2.2。

    我不知道具体原因,但我更改了 launch.json 以使用我的全局 python 安装,它现在可以运行了。我注意到运行调试器无论如何都会激活虚拟环境,所以这似乎不是问题。这是对我有用的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
            },
        ]
    }
    

    我真正认为重要的唯一变化是 pythonPath,其他一切我都会保留为 VS Code 设置的任何默认值。

    【讨论】:

      猜你喜欢
      • 2018-08-18
      • 1970-01-01
      • 2017-02-15
      • 2021-03-05
      • 2019-04-24
      • 1970-01-01
      • 2020-01-06
      • 2021-01-09
      • 2020-07-30
      相关资源
      最近更新 更多