如何在构建 html 时让 sphinx 在 vi​​rtualenv 中查找模块? [英] How to make sphinx look for modules in virtualenv while building html?

查看:32
本文介绍了如何在构建 html 时让 sphinx 在 vi​​rtualenv 中查找模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的机器上使用 virtualenv 而不是本机环境来构建 html 文档.

I want to build html docs using a virtualenv instead of the native environment on my machine.

我已经进入了 virtualenv,但是当我运行 make html 时,我收到错误消息,说无法导入模块 - 我知道这些错误是由模块引起的在我的本地环境中不可用.在搜索文档(例如 virtualenv)时,如何指定应该使用哪个环境?

I've entered the virtualenv but when I run make html I get errors saying the module can't be imported - I know the errors are due to the module being unavailable in my native environment. How can I specify which environment should be used when searching for docs (eg the virtualenv)?

推荐答案

这里的问题是 make html 使用 sphinx-build 命令作为一个普通的 shell 命令,它明确指定在文件的第一行中使用哪个 Python 解释器(即 #!/usr/bin/python).如果以这种方式调用 Python,它将不会使用您的虚拟环境.

The problem here is that make html uses the sphinx-build command as a normal shell command, which explicitly specifies which Python interpreter to use in the first line of the file (ie. #!/usr/bin/python). If Python gets invoked in this way, it will not use your virtual environment.

解决此问题的一种快速而肮脏的方法是从解释器中显式调用 sphinx-build Python 脚本.在 Makefile 中,这可以通过将 SPHINXBUILD 更改为以下内容来实现:

A quick and dirty way around this is by explicitly calling the sphinx-build Python script from an interpreter. In the Makefile, this can be achieved by changing SPHINXBUILD to the following:

SPHINXBUILD   = python <absolute_path_to_sphinx-build-file>/sphinx-build

如果你不想修改你的Makefile,你也可以从命令行传递这个参数,如下:

If you do not want to modify your Makefile you can also pass this parameter from the command line, as follows:

make html SPHINXBUILD='python <path_to_sphinx>/sphinx-build'

现在,如果您在 VirtualEnv 环境中执行 make build,它应该在您的环境中使用 Python 解释器,您应该会看到 Sphinx 找到它需要的所有好东西.

Now if you execute make build from within your VirtualEnv environment, it should use the Python interpreter from within your environment and you should see Sphinx finding all the goodies it requires.

我很清楚这不是一个巧妙的解决方案,因为像这样的 Makefile 不应该假设 sphinx-build 文件的任何特定位置,所以任何建议欢迎提出更合适的解决方案.

I am well aware that this is not a neat solution, as a Makefile like this should not assume any specific location for the sphinx-build file, so any suggestions for a more suitable solution are warmly welcomed.

这篇关于如何在构建 html 时让 sphinx 在 vi​​rtualenv 中查找模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆