2013-07-28 111 views
15

Tôi đang cố gắng tạo tài liệu cho dự án Python thử nghiệm trước khi thực hiện nó cho dự án thực. Hệ thống của tôi: Win7 64 bit, python 2.7.5 64 bit.Nhân sư không tìm thấy gói Python khi sử dụng autodoc

Tên dự án của tôi là testDoc. Nó bao gồm pakage python, có tên là t, bao gồm 2 mô-đun t1t2__init__.py.

__init__.py chứa:

import t1 
import t2 

t1.py chứa:

''' 
Created on 27 2013 

@author: 
''' 

class MyClass(object): 
    ''' 
    Hi 
    ''' 


    def __init__(self,selfparams): 
     ''' 
     Constructor 
     ''' 
     pass 

Để tạo tài liệu tôi chạy trong dòng lệnh trong testDoc:

sphinx-apidoc -A "me" -F -o docs . 

Sphinx tạo ra nhiều các tập tin và nó là ok theo Sphinx d ocs. Sau đó, conf.py được sửa đổi

sys.path.insert(0, os.path.abspath(absolute path to testDoc)) 

tôi nhập docs thư mục và gõ

make html 

và nhận được đầu ra sai lầm sau đây:

Making output directory... 
Running Sphinx v1.1.3 
loading pickled environment... not yet created 
building [html]: targets for 2 source files that are out of date 
updating environment: 2 added, 0 changed, 0 removed 
reading sources... [ 50%] index 
reading sources... [100%] t 
Traceback (most recent call last): 
    File "C:\Python27\lib\site-packages\sphinx\ext\autodoc.py", line 321, in impor 
t_object 
    __import__(self.modname) 
ImportError: No module named t.__init__ 
Traceback (most recent call last): 
    File "C:\Python27\lib\site-packages\sphinx\ext\autodoc.py", line 321, in impor 
t_object 
    __import__(self.modname) 
ImportError: No module named t.t1 
Traceback (most recent call last): 
    File "C:\Python27\lib\site-packages\sphinx\ext\autodoc.py", line 321, in impor 
t_object 
    __import__(self.modname) 
ImportError: No module named t.t2 

...testDoc\t\docs\t.rst:7: WARNING: a 
autodoc can't import/find module 't.__init__', it reported error: "No module name 
d t.__init__", please check your spelling and sys.path 
...testDoc\t\docs\t.rst:15: WARNING: 
autodoc can't import/find module 't.t1', it reported error: "No module named t.t 
1", please check your spelling and sys.path 
t...testDoc\t\docs\t.rst:23: WARNING: 
autodoc can't import/find module 't.t2', it reported error: "No module named t.t 
2", please check your spelling and sys.path 
looking for now-outdated files... none found 
pickling environment... done 
checking consistency... done 
preparing documents... done 
writing output... [ 50%] index 
writing output... [100%] t 

writing additional files... (0 module code pages) genindex search 
copying static files... done 
dumping search index... done 
dumping object inventory... done 
build succeeded, 3 warnings. 

Build finished. The HTML pages are in _build/html. 

Có chuyện gì vậy? Cảm ơn.

+0

tôi đoán là có cái gì đó sai với 'đường dẫn tuyệt đối đến testDoc'. Bạn không thể sử dụng 'os.path.abspath (" .. ")'? – mzjn

+0

@mzjn Cảm ơn. Tuy nhiên, cùng một vấn đề xảy ra. – user1264304

Trả lời

19

Tôi không biết "đường dẫn tuyệt đối cho testDoc" là gì, nhưng từ đầu ra Sphinx tôi có thể thấy cấu trúc thư mục testDoc là testDoc/t/docs. Thư mục docs là nơi mà conf.py.

Đối với các đường dẫn tìm kiếm mô-đun được thiết lập đúng cách, bạn cần phải đi hai cấp độ lên từ conf.py:

sys.path.insert(0, os.path.abspath("../..")) 
+0

@ mzjn Cảm ơn bạn. Nó đã làm việc. Với con đường tuyệt đối nó không. – user1264304

+0

Tôi đã làm điều đó, thêm đường dẫn làm các mô-đun, nhưng vẫn còn, nó biên dịch và không có mô-đun hiển thị! Có suy nghĩ gì không? –

+0

@PedroBraz: Thật khó để đưa ra một gợi ý tốt. Mọi dự án đều khác nhau và tôi không biết gì về bạn. – mzjn