python - django-rest-framework + swagger ui : ImportError: No module named rest_framework_swagger

标签 python django django-rest-framework swagger-ui

我正在尝试将 django-rest-swagger ui 添加到我的 api,但我得到了 ImportError: No module named rest_framework_swagger 即使我已经完成了 pip install django -休息大摇大摆。我还可以通过 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

最佳答案

按照以下步骤解决:

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

2- 使用 pip 安装需求或 rest_framework_swagger

    pip install django-rest-swagger

3- 在 File-> Settings -> Project Interpreter -> : 为你的项目选择虚拟环境
4- 在工具栏 -> Edit configurations...-> python Interpreter : 选择你的项目虚拟环境

关于python - django-rest-framework + swagger ui : ImportError: No module named rest_framework_swagger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27369314/

相关文章:

python - 如何按元素乘以矩阵列表?

django - 当已经有ID字段时,如何使UUID字段成为默认字段

python-3.x - 属性错误: 'module' object has no attribute 'packages'

python - Python 图像库在 PyPI 上不可用,还是我遗漏了什么?

python - Django : An established connection was aborted by the software in your host machine

python - 在 Django 中使用 DateTimeField 与 Oracle

python - 如何在 Django Rest Framework 中为 ListField 传递多个值?

python - 如何使 Python 请求包的响应成为 "file-like object"

python - requirements.txt 与 setup.py

python - 用另一个列表的内容替换列表项