2017-08-03 52 views
2

我試圖在https://readthedocs.org/上構建文檔。readthedocs上的獅身人面像autodoc:ImportError:沒有名爲_tkinter的模塊

我看不到任何導入matplotlib的文件的docstrings。

當我看着生成日誌,我看到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管理員>高級設置)頁面,以便:

  • 該項目應該建在virtualenv
  • 該項目應使用requirements.txt文件,其中包括matplotlib構建。你也可以看到它已經從上面的消息中安裝 - 只是顯然不正確。

以前任何人都遇到過這種情況,並知道如何解決它?

Tkinter: "Python may not be configured for Tk"的答案沒有幫助,因爲這是關於readthedocs的。

回答

1

MERose的解決方案可能是最好的,但如果它不能在這裏工作是爲我工作的另一個解決方法:

你可以只讓用「AGG」後端,它不需要Tkinter的,獅身人面像使用進口matplotlib打開<project root>/docs/source/conf.py和插入線:

import matplotlib 
matplotlib.use('agg') 

最後。