Django rest framework+swagger ui:importorror:没有名为rest_framework_swagg的模块

2024-05-16 15:14:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将django rest swagger ui添加到我的api中,但是我得到了ImportError: No module named rest_framework_swagger,尽管我已经完成了pip install django-rest-swagger。我还可以通过pip list看到virtualenv上安装的包。我也试过python manage.py syncdb,但实际上什么也没做。有人给我提些建议吗?谢谢。

INSTALLED_APPS = (
'rest_framework',
'at_api',
'rest_framework_swagger',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)

编辑:系统路径信息

>>> import sys
>>> for p in sys.path: print p
...

C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\psycopg2-2.5.3-py2.7-win-amd64.egg
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\six-1.8.0-py2.7.egg
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\cssselect-0.9.1-py2.7.egg
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\pyopenssl-0.14-py2.7.egg
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\lxml-3.4.1-py2.7-win-amd64.egg
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\queuelib-1.2.2-py2.7.egg
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\w3lib-1.10.0-py2.7.egg
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\twisted-14.0.2-py2.7-win-amd64.egg
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\zope.interface-4.1.1-py2.7-win-amd64.egg
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\zipline-0.7.0-py2.7.egg
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\pandas-0.15.1-py2.7-win-amd64.egg
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\pywin32-214-py2.7-win-amd64.egg
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages\pyyaml-3.11-py2.7-win-amd64.egg
C:\windows\system32\python27.zip
C:\Users\Andrew\.virtualenvs\adventure_time\DLLs
C:\Users\Andrew\.virtualenvs\adventure_time\lib
C:\Users\Andrew\.virtualenvs\adventure_time\lib\plat-win
C:\Users\Andrew\.virtualenvs\adventure_time\lib\lib-tk
C:\Users\Andrew\.virtualenvs\adventure_time\Scripts
C:\Python27\Lib
C:\Python27\DLLs
C:\Python27\Lib\lib-tk
C:\Users\Andrew\.virtualenvs\adventure_time
C:\Users\Andrew\.virtualenvs\adventure_time\lib\site-packages
>>>

回溯:

Traceback (most recent call last):
  File "C:/Users/Andrew/Desktop/rocketu/adventure_time/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 280, in execute
    translation.activate('en-us')
  File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", line 130, in activate
    return _trans.activate(language)
  File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 188, in activate
    _active.value = translation(language)
  File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 177, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 159, in _fetch
    app = import_module(appname)
  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in import_module
    __import__(name)
ImportError: No module named rest_framework_swagger

Process finished with exit code 1

Tags: djangoinpytimeegglibpackagesline
3条回答

面对同样的问题。通过使用pip安装rest_framework掴u swagger解决了这个问题

按照以下步骤解决:

1-确保您的虚拟环境已激活。

2-使用pip安装需求或rest框架

    pip install django-rest-swagger

3-在文件中->;设置->;项目解释程序->;:为项目选择虚拟环境
4-在工具栏中->;编辑配置…->;python解释器:选择项目虚拟环境

解决了。。。这比我想象的要简单得多。我刚刚查看了我的项目的解释器,我注意到它没有使用安装了django rest swagger的virtualenv。

相关问题 更多 >