Home > Back-end >  ModuleNotFoundError: No module named '_curses' erorr during import views in Django 4
ModuleNotFoundError: No module named '_curses' erorr during import views in Django 4

Time:09-29

I'm new in Django 4, trying to learn it via the book. I get error ModuleNotFoundError: No module named '_curses' when I import views in url.py and run server with python manage.py runserver. For some time it worked fine without any errors but suddenly stopped. This is the code of url.py:

from django.contrib import admin
from django.urls import path
from movie import views as movieViews

urlpatterns = [
    path('admin/', admin.site.urls),
    # path('', movieViews.home),
    # path('about/', movieViews.about),
]

Commented code does no effect, the problem is in line from movie import views as movieViews, if I comment it - no error. This is an error:

E:\Files\Coding\Python\Django4 for impatient\mrprg>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\commands\runserver.py", line 134, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 475, in check
    all_issues = checks.run_checks(
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\urls.py", line 42, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\urls.py", line 61, in _load_all_namespaces
    url_patterns = getattr(resolver, "url_patterns", [])
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 715, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 708, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "E:\Files\Coding\Python\Django4 for impatient\mrprg\moviereviews\urls.py", line 18, in <module>
    from movie import views
  File "E:\Files\Coding\Python\Django4 for impatient\mrprg\movie\views.py", line 1, in <module>
    from curses.ascii import HT
  File "C:\Users\OM\AppData\Local\Programs\Python\Python310\lib\curses\__init__.py", line 13, in <module>
    from _curses import *
ModuleNotFoundError: No module named '_curses'

This is project's structure

enter image description here

In other threads I saw I should use Python 3.8 (like I should to downgrade... such a wierd practice, I saw that _curses module didn't update for 2 years!), and this error only with Windows. But I really can't understand where this module _curses come from, I just import one file to another. I'm using Python 3.10.2, VScode, Django 4.1.1, Win 10. I didn't use any virtual environments (even don't know what is it so far).

CodePudding user response:

You can try:

pip install windows-curses

... if this doesn't work it could be an issue with your Python interpreter. Make sure that your IDE is selecting the currect interpreter.

  • Related