[英]Sphinx autodoc on readthedocs: ImportError: No module named _tkinter
我正在嘗試在https://readthedocs.org/上構建文檔。
我無法看到導入matplotlib的任何文件的文檔字符串。
當我查看構建日志時,我看到from matplotlib import pyplot as plt
失敗,並顯示以下消息:
/home/docs/checkouts/readthedocs.org/user_builds/artemis-ml/checkouts/latest/docs/source/plotting.rst:67: WARNING: autodoc: failed to import function u'dbplot' from module u'artemis.plotting.db_plotting'; the following exception was raised:
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/artemis-ml/envs/latest/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 551, in import_object
__import__(self.modname)
File "/home/docs/checkouts/readthedocs.org/user_builds/artemis-ml/envs/latest/lib/python2.7/site-packages/artemis_ml-1.6-py2.7.egg/artemis/plotting/db_plotting.py", line 3, in <module>
from artemis.plotting.matplotlib_backend import BarPlot
File "/home/docs/checkouts/readthedocs.org/user_builds/artemis-ml/envs/latest/lib/python2.7/site-packages/artemis_ml-1.6-py2.7.egg/artemis/plotting/matplotlib_backend.py", line 7, in <module>
from matplotlib import pyplot as plt
File "/home/docs/checkouts/readthedocs.org/user_builds/artemis-ml/envs/latest/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/home/docs/checkouts/readthedocs.org/user_builds/artemis-ml/envs/latest/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/home/docs/checkouts/readthedocs.org/user_builds/artemis-ml/envs/latest/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
from six.moves import tkinter as Tk
File "/home/docs/checkouts/readthedocs.org/user_builds/artemis-ml/envs/latest/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/home/docs/checkouts/readthedocs.org/user_builds/artemis-ml/envs/latest/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/home/docs/checkouts/readthedocs.org/user_builds/artemis-ml/envs/latest/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
File "/home/docs/.pyenv/versions/2.7.13/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
我已經指定(在readthedocs管理>高級設置中)頁面,以便:
requirements.txt
文件構建。 您還可以看到它已從上面的消息安裝 - 只是顯然不正確。 有人之前遇到過這個並且知道如何修復它嗎?
Tkinter的答案:“可能沒有為Tk配置Python”沒有幫助,因為這是關於readthedocs。
您可以使用模擬導入來解決此問題。
Sphinx提供此功能來自動生成此處所述的文檔。 只需在conf.py
開頭寫一下
autodoc_mock_imports = ['_tkinter']
這里有一個例子: https : //github.com/scopus-api/scopus/blob/4bb7f62f7a94e652f77515c94e7e0bab0d07cce7/docs/conf.py#L24
MERose的解決方案可能是最好的,但如果它不起作用,另一種解決方法對我有用:
你可以通過打開<project root>/docs/source/conf.py
並插入行來讓sphinx使用導入matplotlib和'agg'后端,它不需要<project root>/docs/source/conf.py
。
import matplotlib
matplotlib.use('agg')
在末尾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.