没有名为rest_framework的模块

Cyr*_*osi 2 python django pip python-3.x django-rest-framework

我看到很多人在这里遇到了麻烦,我总是看到他们说其他使用 pip3 或只是 pip 来安装它。

\n\n

但就我而言,我已经卸载它并使用 pip 或 pip3 多次安装 id ,但它们似乎都不起作用。

\n\n

我也将“rest_framework”添加到我的设置中,但似乎仍然不起作用。\n请帮助我

\n\n
EDIT\nHere is my settings\n\nINSTALLED_APPS = [\n    \'django.contrib.admin\',\n    \'django.contrib.auth\',\n    \'django.contrib.contenttypes\',\n    \'django.contrib.sessions\',\n    \'django.contrib.messages\',\n    \'django.contrib.staticfiles\',\n    \'agenda.apps.AgendaConfig\',\n    \'rest_framework\',\n\n]\n\nREST_FRAMEWORK = {\n    # Use Django\'s standard `django.contrib.auth` permissions,\n    # or allow read-only access for unauthenticated users.\n    \'DEFAULT_PERMISSION_CLASSES\': [\n        \'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly\'\n    ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n

收集 djangorestframework 下载\n djangorestframework-3.7.3-py2.py3-none-any.whl (1.5MB)\n 100% |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\ x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\ x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\ xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\ x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 1.5MB 506kB/s 安装收集的软件包:djangorestframework 已成功安装\n djangorestframework-3.7.3

\n
\n\n

还是行不通

\n\n

编辑2

\n\n
> Traceback (most recent call last):   File\n> "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py",\n> line 226, in wrapper\n>     fn(*args, **kwargs)   File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py",\n> line 121, in inner_run\n>     self.check(display_num_errors=True)   File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",\n> line 374, in check\n>     include_deployment_checks=include_deployment_checks,   File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",\n> line 361, in _run_checks\n>     return checks.run_checks(**kwargs)   File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py",\n> line 81, in run_checks\n>     new_errors = check(app_configs=app_configs)   File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py",\n> line 14, in check_url_config\n>     return check_resolver(resolver)   File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py",\n> line 24, in check_resolver\n>     for pattern in resolver.url_patterns:   File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py",\n> line 35, in __get__\n>     res = instance.__dict__[self.name] = self.func(instance)   File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py",\n> line 313, in url_patterns\n>     patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)   File\n> "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py",\n> line 35, in __get__\n>     res = instance.__dict__[self.name] = self.func(instance)   File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py",\n> line 306, in urlconf_module\n>     return import_module(self.urlconf_name)   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module\n>     __import__(name)   File "/home/cyro/PycharmProjects/MyClinic/MyClinic/urls.py", line 20, in\n> <module>\n>     url(r\'^agenda/\', include(\'agenda.urls\')),   File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py",\n> line 50, in include\n>     urlconf_module = import_module(urlconf_module)   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module\n>     __import__(name)   File "/home/cyro/PycharmProjects/MyClinic/agenda/urls.py", line 3, in\n> <module>\n>     from . import views   File "/home/cyro/PycharmProjects/MyClinic/agenda/views.py", line 8, in\n> <module>\n>     import rest_framework ImportError: No module named rest_framework\n
Run Code Online (Sandbox Code Playgroud)\n

gui*_*rro 5

尝试使用sudo pip install djangorestframework,我见过其他SO问题,它似乎解决了问题。