Gerard22
Gerard22

Reputation: 363

Django - cannot import name path

So i'm starting to use Django but i had some problems trying to run my server. I have two versions of python installed. So in my mysite package i tried to run python manage.py runserver but i got this error:

   Unhandled exception in thread started by <function wrapper at 0x058E1430>
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Python27\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Python27\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "C:\Python27\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
    return check_method()
  File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\Users\Davide\Desktop\django-proj\mysite\mysite\urls.py", line 17, in <module>
    from django.urls import path
ImportError: cannot import name path

Is it because i have two versions installed?

Upvotes: 1

Views: 11364

Answers (3)

Cyebukayire
Cyebukayire

Reputation: 948

You need to upgrade Django

pip install --upgrade django
pip3 install --upgrade django

Upvotes: 0

aless80
aless80

Reputation: 3332

Have you tried to upgrade django with pip or pip3?

pip install --upgrade django --user

Upvotes: 0

Shubho Shaha
Shubho Shaha

Reputation: 2139

Not sure what django version you are currently using but if you are working with Django 2.0 then python2 wouldn't work ( Cause Django2.0 support only Python 3.4+)

So in your case if you are in Django2.0 (assuming you already have installed latest version of python in your machine) then you should run following command.

python3 manage.py runserver

Or install python3 instead of python2 in your virtual environment. Then hopefully your command

python manage.py runserver

will work perfectly.

Upvotes: 3

Related Questions