Error "Couldn't import Django" running MS Visual Code Tutorial

I am a newbie to coding and MS Visual Studio Code and trying to learn Django using MS Visual Studio Code (VCS) tutorial: https://code.visualstudio.com/docs/python/tutorial-django on a Dell XPS running Windows11 Home.

I have successfully completed the first section to get Django running from VSC using:

Terminal Window: python manage.py runserver

Edge Browser: http://127.0.0.1:8000/

The Browser displays: Hello, Django!

Then I try to use the VCS debugger and get the following error:

Exception has occurred: ImportError •
Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment? File "C:\Users\Mark\Dropbox\Coding\Udemy\ToDo\manage.py", line 11, in main from django.core.management import execute_from_command_line ModuleNotFoundError: No module named 'django' The above exception was the direct cause of the following exception: File "C:\Users\Mark\Dropbox\Coding\Udemy\ToDo\manage.py", line 13, in main "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" ) from exc execute_from_command_line(sys.argv) File "C:\Users\Mark\Dropbox\Coding\Udemy\ToDo\manage.py", line 22, in main() ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

I created a launch.json file using the following options:

  1. Python Debugger

    a. Django

    b. manage.py

launch.json file:

{
    // 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 Debugger: Django",
            "type": "debugpy",
            "request": "launch",
            "args": [
                "runserver"
            ],
            "django": true,
            "autoStartBrowser": false,
            "program": "${workspaceFolder}\\manage.py"
        }
    ]
}

Any help would be appreciated.

Back to Top