0
votes

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. I would run the project in the Integrated Terminal using manage.py runserver after activating my virtual environment and that worked. I created a debug configuration with the default launch.json for django projects. 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.

1

1 Answers

0
votes

Note: I'm running Windows 10, python 3.6 and 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. 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:

{
    // 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.