Django Error While Trying to Create Superuser

Error

When I tried to run this command: python manage.py createsuperuser in my Django project, it gave me a super long error which included the following:

File “manage.py”, line 22, in
main()
File “manage.py”, line 18, in main
execute_from_command_line(sys.argv)
File “/Users/username/.local/share/virtualenvs/django-learn-csZU2bYZ/lib/python3.8/site-packages/django/core/management/init.py”, line 364, in execute_from_command_line
utility.execute()

….

ImportError: cannot import name ‘path’ from ‘django.urls’ (/Users/username/.local/share/virtualenvs/django-learn-csZU2bYZ/lib/python3.8/site-packages/django/urls/init.py)

Solution

The problem in my case was that I had the wrong version of Django installed. In order to run the python manage.py createsuperuser command you need at least Django 2.

Run this command to check the version of Django you are currently working with:

python -m django --version 

Run this command to install the latest version of Django.

pip install --upgrade django

Run the python -m django --version command again and make sure your new Django version is 2.x or above. If so, you should be able to run python manage.py createsuperuser now

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s