126

私は Sphinx を使い始めようとしていますが、容赦ない問題を抱えているようです。

指示:docs/sphinx-quickstart

私はすべての質問に答え、すべてがうまくいきます。

指示:docs/ls

すべてが正常に見えます。結果:build Makefile source

指示:sphinx-build -d build/doctrees source build/html

うまくいくようです。index.html ファイルを開くと、必要な「シェル」が表示されました。

実際のソース コードをsourceフォルダーとして配置しようとすると、問題が発生します。

指示:sphinx-build -d build/doctrees ../ys_utils build/html

結果:

Making output directory...
Running Sphinx v1.1.3
loading pickled environment... not yet created
No builder selected, using default: html
loading intersphinx inventory from http://docs.python.org/objects.inv...
building [html]: targets for 1 source files that are out of date
updating environment: 1 added, 0 changed, 0 removed
Traceback (most recent call last):                                                                                               
  File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
ImportError: No module named ys_utils
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
ImportError: No module named ys_utils.test_validate_ut
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
ImportError: No module named ys_utils.git_utils
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
ImportError: No module named setup.setup

/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:4: WARNING: autodoc can't import/find module 'ys_utils', it reported error: "No module named ys_utils", please check your spelling and sys.path
/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:10: WARNING: autodoc can't import/find module 'ys_utils.test_validate_ut', it reported error: "No module named ys_utils.test_validate_ut", please check your spelling and sys.path
/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:12: WARNING: don't know which module to import for autodocumenting u'UnitTests' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)
/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:18: WARNING: autodoc can't import/find module 'ys_utils.git_utils', it reported error: "No module named ys_utils.git_utils", please check your spelling and sys.path
/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:24: WARNING: autodoc can't import/find module 'setup.setup', it reported error: "No module named setup.setup", please check your spelling and sys.path
WARNING: master file /home/ricomoss/workspace/nextgen/ys_utils/index.rst not found
looking for now-outdated files... none found
pickling environment... done
checking consistency... /home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:: WARNING: document isn't included in any toctree
done
preparing documents... done
writing output... [ 50%] index                                                                                                   
Exception occurred:
  File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/environment.py", line 1213, in get_doctree
    f = open(doctree_filename, 'rb')
IOError: [Errno 2] No such file or directory: '/home/ricomoss/workspace/nextgen/docs/build/doctrees/index.doctree'
The full traceback has been saved in /tmp/sphinx-err-jjJ7gM.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
Either send bugs to the mailing list at <http://groups.google.com/group/sphinx-dev/>,
or report them in the tracker at <http://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks!

私は Sphinx の完全な初心者であり、この種のドキュメントには比較的慣れていません。誰でもいくつかの提案を提供できますか?

編集:

これを処理するために Makefile を使用できるようにしたいと思います。現在、プロジェクトには 2 つのフォルダーがあります。

nextgen/ls

docs ys_utils

および今後使用する他のすべてのモジュールnextgen/docs/Makefileの HTML を生成する必要があります。ys_utils

4

9 に答える 9

108

モジュールが にないため、Autodoc はモジュールを見つけることができませんsys.path

にモジュールへのパスを含める必要がありsys.pathますconf.py。の上部conf.py(のインポート直後sys)を見てsys.path.insert()ください。適応できるステートメントがあります。

ちなみに、Makefilecreated by Sphinx を使用してドキュメントを作成できます。電話するだけ

make

をクリックしてオプションを表示します。

試す前に何か問題があった場合:

make clean

実行する前にmake html

于 2012-04-27T13:59:15.013 に答える
31

conf.py

プロジェクトフォルダーへのパスを追加するだけです。

sys.path.append('/home/workspace/myproj/myproj')
于 2012-09-03T10:47:36.297 に答える
3

理由はわかりませんが (私の場合、autodoc がパッケージをインストールできなかったのかもしれません)、module-not-foundモジュールを含むすべてのディレクトリをパスに明示的に含めるまで、常にエラーが発生しました。

次の例のフォルダー構造の場合

project_dir
|- setup.py
|- src
|  |- __init__.py
|  |- source1.py
|  |- sub_project
|     |- __init__.py
|     |- source2.py 
|- docs
    |- conf.py
    |- source
    |  |- index.rst
    |- _build       

私が含めた

for x in os.walk('../../src'):
  sys.path.insert(0, x[0])

conf.py関連するすべてのディレクトリが追加されるように、そのようなものの先頭に。

于 2020-12-03T12:02:05.963 に答える
1

toctreeにファイルを追加しようとしたときに初めてこれを行ったと思います。:maxdepth行とファイル名の間の空白行を省略したためだと思います。

.. Animatrix Concepts documentation master file, created by
   sphinx-quickstart on Thu Mar 22 18:06:15 2012.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to Animatrix Concepts documentation!
============================================

Contents:

.. toctree::
   :maxdepth: 2

   stuff


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

上記は私のindex.rstファイルです。stuff.rstは、それと同じディレクトリにあります。

于 2012-04-25T22:02:40.337 に答える
0

Pweaveおよび noweb フォーマットを使用して、埋め込まれたコードの出力を含む最初のドキュメントを生成できます。基本的に、次のようにマークされたチャンクに Python コードを埋め込んで、最初のファイルを作成します。

<<echo=False>>=
print("some text that will appear in the rst file")
@

Pweave はこれらのチャンクを実行し、結果の rst ファイルの出力に置き換えます。これを sphinx で使用できます。外観の詳細については、Pweave reST の例を参照してください。

于 2015-10-08T03:52:57.500 に答える