如何调试ImportError“No Module named ...”

时间:2014-11-21 16:18:26

标签: python django django-rest-framework

我正在使用Django Rest Framework。当我尝试去swagger docs页面时, 我正进入(状态 ImportError:没有名为drf_compound_fields的模块

from  serializers.py where I try to import the following

from drf_compound_fields.fields import ListField

我的virtualenv中有drf-compound-field 0.2.2,我运行了pip list命令以确保它已安装。

以下是我从manage.py shell获得的内容

 Python 2.7.6 (default, Mar 22 2014, 22:59:56)   
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> 
>>> 
>>> 
>>> 
>>> from drf_compound_fields.fields import ListField
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named drf_compound_fields.fields
>>> 

感谢您的帮助!!

1 个答案:

答案 0 :(得分:0)

drf-compound-fields安装在运行django服务器的相同virtualenv下。 显然,它需要在系统级别安装,而不一定是在virtualenv级别。

按照以下步骤在系统级安装drf-compound-fields软件包:

  1. 停用virtualenv。
  2. pip install def-compound-fields
  3. 激活virtualenv并启动django进程