[英]django-rest-framework + swagger ui: ImportError: No module named rest_framework_swagger
I'm trying to add django-rest-swagger ui to my api, but I'm getting ImportError: No module named rest_framework_swagger
even though I've already done pip install django-rest-swagger
. 我试图将django-rest-swagger ui添加到我的api中,但是我得到了
ImportError: No module named rest_framework_swagger
即使我已经完成了pip install django-rest-swagger
也ImportError: No module named rest_framework_swagger
。 I can also see the package installed on my virtualenv through pip list
. 我还可以通过
pip list
查看安装在我的virtualenv上的软件包。 I've tried python manage.py syncdb
as well but doesn't really do anything. 我也尝试过
python manage.py syncdb
,但实际上并没有做任何事情。 Anyone have some suggestions for me? 有人对我有什么建议吗? Thanks.
谢谢。
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',
)
EDIT: Sys path info 编辑:系统路径信息
>>> 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: 追溯:
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
Solved it... It was way more simpler than I had imagined. 解决了...比我想象的要简单得多。 I just checked to see my project's interpreter, and I noticed that it was not using my virtualenv with django-rest-swagger installed.
我只是检查了项目的解释器,然后注意到它没有使用安装了django-rest-swagger的virtualenv。
Follow these steps to solve: 请按照以下步骤解决:
1- Make sure your Virtual Environment is activated. 1-确保您的虚拟环境已激活。
2- install requirements or rest_framework_swagger using pip 2-安装要求或使用pip的rest_framework_swagger
pip install django-rest-swagger
3- in File-> Settings -> Project Interpreter -> : select virtual environment for your project 3-在File-> Settings-> Project Interpreter->中:为您的项目选择虚拟环境
4- in toolbar -> Edit configurations...-> python Interpreter : select your project virtual environment 4-在工具栏中->编辑配置...-> python解释器:选择项目虚拟环境
Faced the same issue. 面临同样的问题。 Solved it by installing the rest_framework_swagger using pip
通过使用pip安装rest_framework_swagger解决了它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.