如何在ReadTheDocs中将matplotlib的plot-directive与python-3一起使用?

安科斯蒂斯

我有一个python-3项目,该项目使用plot指令即时生成和嵌入matplotlib的图,并且使用ReadTheDocs自动生成该项目的文档。在python-2中
plot-directive确实可以正常工作,但目前在python-3中失败。

具体来说,我在RTD日志中遇到的故障是:

建立标准错误

html
-----

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/wltp/envs/master/lib/python3.4/site-packages/sphinx/application.py", line 325, in setup_extension
    mod = __import__(extension, None, None, ['setup'])
ImportError: No module named 'matplotlib'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/wltp/envs/master/lib/python3.4/site-packages/sphinx/cmdline.py", line 253, in main
    warningiserror, tags, verbosity, parallel)
  File "/home/docs/checkouts/readthedocs.org/user_builds/wltp/envs/master/lib/python3.4/site-packages/sphinx/application.py", line 119, in __init__
    self.setup_extension(extension)
  File "/home/docs/checkouts/readthedocs.org/user_builds/wltp/envs/master/lib/python3.4/site-packages/sphinx/application.py", line 328, in setup_extension
    err)
sphinx.errors.ExtensionError: Could not import extension matplotlib.sphinxext.plot_directive (exception: No module named 'matplotlib')

Extension error:
Could not import extension matplotlib.sphinxext.plot_directive (exception: No module named 'matplotlib')

罪魁祸首可以追溯到由于遗忘了“ freetype” C库而未编译的matplotlib:

设定输出

...

requirements
-----
...
BUILDING MATPLOTLIB
            matplotlib: yes [1.4.2]
                python: yes [3.4.0 (default, Apr 11 2014, 13:05:11)  [GCC
                        4.8.2]]
              platform: yes [linux]

REQUIRED DEPENDENCIES AND EXTENSIONS
                 numpy: yes [not found. pip may install it below.]
                   six: yes [six was not found.]
              dateutil: yes [dateutil was not found. It is required for date
                        axis support. pip/easy_install may attempt to
                        install it after matplotlib.]
                  pytz: yes [pytz was not found. pip will attempt to install
                        it after matplotlib.]
               tornado: yes [tornado was not found. It is required for the
                        WebAgg backend. pip/easy_install may attempt to
                        install it after matplotlib.]
             pyparsing: yes [pyparsing was not found. It is required for
                        mathtext support. pip/easy_install may attempt to
                        install it after matplotlib.]
                 pycxx: yes [Official versions of PyCXX are not compatible
                        with matplotlib on Python 3.x, since they lack
                        support for the buffer object.  Using local copy]
                libagg: yes [pkg-config information for 'libagg' could not
                        be found. Using local copy.]
              freetype: no  [The C/C++ header for freetype2 (ft2build.h)
                        could not be found.  You may need to install the
                        development package.]    
    OPTIONAL LATEX DEPENDENCIES
                dvipng: yes [version 1.14]
           ghostscript: yes [version 9.10]
                 latex: yes [version 3.1415926]
               pdftops: no

============================================================================
                        * The following required packages can not be built:
                        * freetype

为了使文档生成过程顺利进行,我不得不按照RTD FAQ中的说明,使用./conf.py文件中的以下代码,通过模拟来“禁用”绘图指令

我尝试了各种组合virtualenv(具有或不具有站点包可见性),特定requirements.txtrtd的方法,但均未成功。

有没有人找到办法?

这些是那些愿意进一步研究该问题的提示:

安科斯蒂斯

从今天起,根据rtfd问题#896,该问题已正式解决python-3也安装了所有必需的依赖项(matplotlib,scipy和numpy),因此不再需要模拟。

要使用它,请Advanced settings进行以下选择:

  • 检查: Install Project: Install your project inside a virtualenv using setup.py install
  • 选择: Python interpreter: CPython 3.x
  • 检查:Use system packages: Give the virtual environment access to the global site-packages dir

...尽管经过一些培训,但编写python-2 / 3兼容代码很容易

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Python中与networkx和matplotlib一起使用“边缘捆绑”?

如何在OSX 10.6中将MySQLdb与Python和Django一起使用?

如何在Python 3中将CSV编写器与GZIP文件一起使用?

在AMD GPU中将Python + Theano与OpenCL一起使用

如何在Python中将if语句与数组一起使用?

在Python中将OpenCL加速功能与OpenCV3一起使用

在Python 3中将textwrap.dedent()与字节一起使用

如何在python中将列表理解与矩阵一起使用?

如何在Python中将C函数与复杂类型一起使用?

Power BI:如何在Power Query Editor中将Python与多个表一起使用?

如何在熊猫,python3中将条件与其他行(时间序列数据中的先前时刻)一起使用

如何在python中将文本分类与数据框一起使用

在Python 3中将gzip与包含多个文件的存档一起使用

如何在Keras Python中将TF IDF矢量器与LSTM一起使用

在Python中将Dicom图像与OpenCV一起使用

在Unity3D游戏脚本中将Python脚本与PIP包一起使用

在Python中将knnMatch与opencv一起使用时出错

如何在python中将GridSearchCV与管道和超参数一起使用

如何在Python中将索引与itertools函数一起使用

如何在python中将argparse与json文件一起使用

在Python中将min(,[,key])与多个参数一起使用

如何在OSX中将OpenCV与python一起使用?

如何在不使用SQLAlchemy的Flask(Python)中将SQL与Postgresql命令一起使用

如何在python中将SHGetFileInfo与SHGFI_PIDL一起使用

如何将Selenium与别名Python 3一起使用

如何在Python中将3个元组组合在一起

如何在 Python 中将 Requests 库与 Selenium 一起使用

如何在 python 3 中将菜单连接在一起并在它们之间导航?

如何在 Python 中将 rsplit 与 None 值一起使用?