Reputation: 7895
I'm going though this tutorial: https://github.com/encode/django-rest-framework
I make all of the changes, but when I get to the runserver
part, I keep getting ModuleNotFoundError: No module named 'rest-framework'
error..
| => ./manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/site-packages/django/urls/resolvers.py", line 584, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/site-packages/django/urls/resolvers.py", line 577, in urlconf_module
return import_module(self.urlconf_name)
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Volumes/thunderb/attic/Projects/VS/maione/maione/urls.py", line 36, in <module>
url(r'^api-auth/', include('rest-framework.urls', namespace='rest_framework')),
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/Volumes/thunderb/attic/Projects/VS/maione/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'rest-framework'
^C(env) ________________________________________________________________________________
| /Volumes/thunderb/attic/Projects/VS/maione @ TRUHQWSOSX3 (agraf)
| => python
Python 3.7.4 (default, Sep 7 2019, 18:27:02)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import rest_framework as rf
>>> dir(rf)
['HTTP_HEADER_ENCODING', 'ISO_8601', 'RemovedInDRF311Warning', 'RemovedInDRF312Warning', 'VERSION', '__author__', '__builtins__', '__cached__', '__copyright__', '__doc__', '__file__', '__license__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__title__', '__version__', 'default_app_config']
>>>
settings.py installed apps:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
]
For some reason, I can not get it to run - I keep getting the above error. I've tried installing and reinstalling python
, virtualenv
and trying different directories and env's. No matter what I do, I keep getting this error. I've pip install djangorestframework
probably 10 times trying to get this to work.
On OSX trying out VS Code.
I assumed that by running pip install djangorestframework
that that satisfied dependencies. Do I also need the django-rest-framework
folder? If so, do I put the projectfolder
folder inside of it? Right now, it looks like:
|-env/
|-example/ (project folder)
|-db.sqlite3
|-manage.py
do I also need the django-rest-framework/
in there? I assumed it lived in env/.../site-packages folder?
Please, any ideas where I'm going wrong or suggestions to narrow down the issue would be much appreciated.
Upvotes: 0
Views: 2357
Reputation: 1760
In your urls.py
file, replace:
url(r'^api-auth/', include('rest-framework.urls', namespace='rest_framework')),
by:
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
With an underscore, not a dash on rest_framework
. The stack trace pointed you the faulty line actually :)
Upvotes: 2