django-rest-framework + swagger ui: ImportError: No module named rest_framework_swagger
Asked Answered
B

4

8

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. I can also see the package installed on my virtualenv through pip list. I've tried python manage.py syncdb as well but doesn't really do anything. 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
Brownstone answered 9/12, 2014 at 0:7 Comment(7)
Can you give sys.path content ?Glindaglinka
@KevinBrown Just added it. The django-rest-swagger github repo requirements say Python (2.6.5+, 2.7, 3.2, 3.3, 3.4), Django (1.5.5+, 1.6, 1.7), Django REST framework (2.3.5+), so perhaps this means drf 3.0.0 does not work?Brownstone
Latest version of what? My drf is 3.0.0, and my django-rest-swagger is 0.2.2. I think these are already the most up-to-date versions?Brownstone
@KevinBrown You mean just type in python or python manage.py shell then import rest_framework_bulk? I did that and I just got back ImportError: No module named rest_framework_bulkBrownstone
@Brownstone My bad, you need to import rest_framework_swagger. My hope is that those tracebacks (if there are any) have some extra details.Sinister
@KevinBrown No errors for both shells :/Brownstone
Oh... I figured it out. My project interpreter wasn't actually set up to my virtualenv with django-rest-swagger installed ╰༼=ಠਊಠ=༽╯ Thanks for sticking with me through this @KevinBrown.Brownstone
C
9

Follow these steps to solve:

1- Make sure your Virtual Environment is activated.

2- install requirements or rest_framework_swagger using pip

    pip install django-rest-swagger

3- in File-> Settings -> Project Interpreter -> : select virtual environment for your project
4- in toolbar -> Edit configurations...-> python Interpreter : select your project virtual environment

Cinquain answered 15/5, 2019 at 13:3 Comment(0)
B
3

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.

Brownstone answered 11/12, 2014 at 6:57 Comment(0)
S
0

Faced the same issue. Solved it by installing the rest_framework_swagger using pip

Sachs answered 30/8, 2017 at 2:59 Comment(0)
T
0

FIXED

just run this:

pip install django-rest-swagger
Titanesque answered 14/4, 2023 at 3:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.