skip to Main Content

I’m trying to run a Django app on an Ubuntu VM but when I execute python manage.py runserver I get this error message:

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?

The code is de default of a Django project, ie,

    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise 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?"
        ) from exc

I’ve tried with all of the things described in this post (ie, I’m in a venv reciently created with django installed, checked the django installation, verified that PYTHONPATH is pointing to venv/lib/python3.8/site-packages, etc.) but I still have the error. Any idea?

2

Answers


  1. Chosen as BEST ANSWER

    I've tried installing Django with:

    sudo python3 -m pip install django
    

    and it worked.


  2. Can you run command pip list to check Django is installed?
    if is installed uninstall
    pip uninstall Django
    and then use this command to install again
    python -c "import django"

    and try again with new project

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search