2012-01-15 58 views
3

我已经在我的virtualenv中,并且我确信一切都在python路径上。Sphinx-api无法导入Django项目的模块

(myenv)[email protected]:/var/lib/mydirectory/doc$ sphinx-apidoc -o . ../testproject/ 

Creating file ./testproject.rst. 
Creating file ./testproject.apps.rst. 
# ... and many more .... # 
Creating file ./modules.rst. 

(myenv)[email protected]:/var/lib/mydirectory/doc$ make html 
sphinx-build -b html -d _build/doctrees . _build/html 
Making output directory... 
Running Sphinx v1.1.2 
loading pickled environment... not yet created 
building [html]: targets for 17 source files that are out of date 
updating environment: 17 added, 0 changed, 0 removed 

Traceback (most recent call last):t                     
    File "/var/lib/server/myenv/lib/python2.6/site-packages/sphinx/ext/autodoc.py", line 321, in import_object 
    __import__(self.modname) 
ImportError: No module named webclient.__init__ 
# ... and many more .... # 

/var/lib/mydirectory/doc/testproject.rst:7: WARNING: autodoc can't import/find module 'testproject.__init__', it reported error: "No module named testproject.__init__", please check your spelling and sys.path 
# ... and many more .... # 

当我打开html文件时,我只看到标题和章节标题。没有autodocs。

是什么导致了这个问题?我已经在我的虚拟环境中...

任何想法?我正在使用狮身人面像1.1.2。

谢谢。

回答

2

我不是狮身人面像专家。但答案是非常清晰的恕我直言。

首先,错误消息显示模块不可导入。这意味着一些.py文件中的导入语句是错误的。

可能的原因:

  1. 传统import语句
  2. Inproper import语句
    • 水平深入进口
    • 错字
  3. 模块不是工作在Python路径的

2.b特别感兴趣。如果你是在MYAPP/mysubapp/models.py,并且要导入的myapp/views.py中,你需要提供以下声明:

# myapp/mysubapp/models.py 
import mysite.myapp.view   # correct 
import myapp.view    # incorrect 

检查每一个警告消息,并期待在每个相应的.py文件。找到相应的导入语句,并仔细检查可用性。

现在回到virtualenv问题。在我看来,你的才能也可能是一个主要原因。只看第一个错误:

ImportError: No module named webclient.__init__ 

这是一个该死的问题。仔细检查你的路径变量是否设置正确。

+0

谢谢。你是对的。固定。 – user1012451 2012-01-16 03:45:02