ImportError: Couldn't import django

zanewithspoon
PRO

5 months ago

I'm running a django project with poerty and docker. The build completes successfully and says django is installed, but the deployment fails with the error:

The above exception was the direct cause of the following exception:



Traceback (most recent call last):

  File "/app/django/manage.py", line 22, in 

    main()

  File "/app/django/manage.py", line 13, in main

    raise ImportError(

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?

Traceback (most recent call last):

  File "/app/django/manage.py", line 11, in main

    from django.core.management import execute_from_command_line

ModuleNotFoundError: No module named 'django'

The install confirmation in the build logs:

Installing dependencies from lock file


Package operations: 10 installs, 0 updates, 0 removals


  • Installing asgiref (3.8.1)

  • Installing sqlparse (0.5.3)

  • Installing django (4.2.19)

  • Installing djangorestframework (3.15.2)
  • Installing pyjwt (2.10.1)

  • Installing django-cors-headers (4.7.0)

  • Installing djangorestframework-simplejwt (5.4.0)

  • Installing gunicorn (23.0.0)

  • Installing psycopg2-binary (2.9.10)

  • Installing whitenoise (6.9.0)

It's building and running fine locally

View Deploy details

> ⓘ Deployment information is only viewable by project members and Railway employees.

2 Replies

brunodantas
FREE

2 months ago

Same here


zanewithspoon
PRO

2 months ago

It's a jankey workaround, but I got it working by re-installing dependencies during my deploy custom start command poetry install && poetry run python manage.py...


ImportError: Couldn't import django - Railway Help Station