首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >由于丢失了pandoc,构建文档失败

由于丢失了pandoc,构建文档失败
EN

Stack Overflow用户
提问于 2020-06-15 22:46:43
回答 4查看 3.8K关注 0票数 14

问题所在

当单击readthedocs.io web界面上的" build“时,我很难获得要成功构建的文档,但是它在我的本地机器上构建得很好。为了测试它是否是环境问题,我创建了一个虚拟环境:

代码语言:javascript
运行
复制
conda create virtualenv -n venv
conda env export -n venv
source activate venv

然后,我将requirements.txt文件安装为:

代码语言:javascript
运行
复制
pip install -r requirements.txt

然后跑了

代码语言:javascript
运行
复制
make clean html

在虚拟env和网上构建文档中,我得到了错误:

代码语言:javascript
运行
复制
Notebook error:
PandocMissing in ex_degassing.ipynb:
Pandoc wasn't found.
Please check that pandoc is installed:
http://pandoc.org/installing.html
make: *** [html] Error 2

我搜索并搜索了一个解决方案,但我的最佳猜测是,即使pandoc位于requirements.txt文件中,也不会通过pip安装。我还试图让它从源代码中构建,在我的pandoc文件中用git+git://github.com/jgm/pandoc#egg=pandoc替换git+git://github.com/jgm/pandoc#egg=pandoc,但这不起作用(请参阅下面的文件)。我可以轻松地在本地机器上安装pandoc,但是它无法通过虚拟环境中的requirements.txt文件或readthedocs安装。

我的一些文件

这是我的requirements.txt文件:

代码语言:javascript
运行
复制
sphinx>=1.4
sphinx_rtd_theme
ipykernel
nbsphinx
pandas
pandoc
numpy
matplotlib
ipynb
scipy

我阅读了所有的readthedocs 文档,具有讽刺意味的是,我发现用于构建的文档对于我编码能力有限的人来说是远远不够的。我试着同时制作readthedocs.yml和environment.yaml文件,但是我不知道他们是否在做任何事情,或者是否正确地编写了这些文件。为了完整起见,以下是这些文件:

readthedocs.yml

代码语言:javascript
运行
复制
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2
# Build documentation in the docs/ directory with Sphinx
sphinx:
  configuration: docs/conf.py
python:
  version: 3.7
  install:
    - requirements: docs/requirements.txt

environment.yaml

代码语言:javascript
运行
复制
channels:
  - conda-forge
dependencies:
  - python =3.7
  - pandoc

总而言之

我用readthedocs和sphinx创建了漂亮的文档,但我无法让它建立在网络上。我如何解决:( a)解决安装pandoc的问题(这是问题吗?)或者消除对pandoc的需求(例如,是否有一种方法可以将jupyter笔记本文件包含在我的文档中而不需要pandoc )?怎么做?)?

非常感谢大家的建议!

EN

回答 4

Stack Overflow用户

发布于 2022-03-23 10:36:10

目前它在熊猫的PyPI页面上还没有很好的解释,但是pandoc实际上是用Haskell编写的,而不是Python。您可以用pip install pandoc安装的用于python的pandoc包没有附带pandoc的可执行副本,它只是一个包装器,可以在python中为pandoc提供绑定。它通过对pandoc的系统副本进行shell调用来做到这一点,因此您需要将安装实际pandoc可执行文件的副本单独绑定到您的系统,这样python绑定才能绑定到它!

例如,在Debian/Ubuntu上,除了安装带有apt的python绑定之外,还需要使用pip安装pandoc的系统副本。

代码语言:javascript
运行
复制
sudo apt install pandoc
pip install pandoc

虽然您可以在本地系统上这样做,但这并不是让它在readthedocs上工作的可行解决方案。

与此形成对比的是,conda试图使包工作,而不管您系统的其余部分安装了什么。因此,conda pandoc包附带了pandoc的实际副本,而不是尝试使用pandoc的系统副本。如果您使用的是conda,那么只需要运行一个命令就可以让pandoc在python中工作:

代码语言:javascript
运行
复制
conda install pandoc

如果您使用conda环境作为readthedocs规范(与OP的情况一样),您可以将pandoc添加到conda部分,而不是env的pip部分。

您可以使用pip安装的PyPI上的pandoc软件包实际上不是用于python的官方pandoc包。还有平安度潘多克,它们也是非官方的。

据说pandoc是一个通过python接口安装pandoc的一站式商店。我认为您只需执行pip install py-pandocconda install pandoc,它就可以立即工作,但由于缺乏文档,我不确定。

对于我自己来说,我正在使用Sphinx构建文档。对于构建python文档(包括readthedocs)时安装pandoc的问题,我个人的解决方案是将以下代码块添加到conf.py中。

代码语言:javascript
运行
复制
from inspect import getsourcefile

# Get path to directory containing this file, conf.py.
DOCS_DIRECTORY = os.path.dirname(os.path.abspath(getsourcefile(lambda: 0)))

def ensure_pandoc_installed(_):
    import pypandoc

    # Download pandoc if necessary. If pandoc is already installed and on
    # the PATH, the installed version will be used. Otherwise, we will
    # download a copy of pandoc into docs/bin/ and add that to our PATH.
    pandoc_dir = os.path.join(DOCS_DIRECTORY, "bin")
    # Add dir containing pandoc binary to the PATH environment variable
    if pandoc_dir not in os.environ["PATH"].split(os.pathsep):
        os.environ["PATH"] += os.pathsep + pandoc_dir
    pypandoc.ensure_pandoc_installed(
        quiet=True,
        targetfolder=pandoc_dir,
        delete_installer=True,
    )


def setup(app):
    app.connect("builder-inited", ensure_pandoc_installed)

pypandoc出现在requirements.txt文件中

这告诉Sphinx检查pandoc是否已经在系统路径上,如果它不可用,它将下载并安装一个副本到存储库的docs/bin/pandoc目录中,并将其添加到path中。

票数 8
EN

Stack Overflow用户

发布于 2021-11-16 13:26:24

我也面临着同样的问题。

代码语言:javascript
运行
复制
Notebook error:
PandocMissing in getting_started.ipynb:
Pandoc wasn't found.
Please check that pandoc is installed:
https://pandoc.org/installing.html

无论您是通过pandoc安装pip还是使用conda,似乎都有不同之处。

尝试以下几点:

代码语言:javascript
运行
复制
pip uninstall pandoc
conda install pandoc

使用conda版本解决了我的机器上的问题。

在另一个方面,如果您正在使用poetry,您可能也会遇到相同的错误消息,即PandocMissing

Windows:

通过Windows:https://pandoc.org/installing.html安装https://pandoc.org/installing.html

Linux (用Ubuntu 2204测试):

sudo apt install pandoc

票数 5
EN

Stack Overflow用户

发布于 2022-03-16 19:58:18

第一

代码语言:javascript
运行
复制
pip uninstall pandoc

下一首,

代码语言:javascript
运行
复制
conda install pandoc

只需在Anaconda提示符下完成它,(如有必要,请重新启动内核),并完成!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62398231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档