简体   繁体   English

Python:没有名为 sphinx 的模块错误

[英]Python: No module named sphinx error

I have followed following guide .我遵循了以下指南

$ pip install sphinx sphinx-autobuild
$ pip freeze | grep "sphinx"
sphinx-autobuild==0.6.0
sphinxcontrib-websupport==1.0.0

$ cd docs
$ sphinx-quickstart
$ make html

make html gives following error: make html给出以下错误:

/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named sphinx
make: *** [help] Error 1

[Q] How could I prevent this error from happening? [Q]我怎样才能防止这个错误发生?

Thank you for your valuable time and help.感谢您的宝贵时间和帮助。

I had the same issue, and I thought it might be helpful to share the solution I found.我遇到了同样的问题,我认为分享我找到的解决方案可能会有所帮助。

Open the Makefile file, and change the following line:打开Makefile文件,并更改以下行:

SPHINXBUILD = python -msphinx

To this one:对此:

SPHINXBUILD = python3 -msphinx

First, don't install anything into your system's Python.首先,不要在系统的 Python 中安装任何东西。 Use either a virtual environment or your system's user installs to isolate packages from the system Python.使用虚拟环境或系统的用户安装将软件包与系统 Python 隔离。 The Python Packaging Authority provides an explanation of why virtual environments are a good idea™ . Python Packaging Authority 解释了为什么虚拟环境是一个好主意™

I prefer to start by installing another version of Python on my system, either using the official installers for macOS (beginner) or pyenv (not beginner).我更喜欢首先在我的系统上安装另一个版本的 Python,使用macOS官方安装程序(初学者)或pyenv (非初学者)。 Install Python 3.x unless you absolutely must use Python 2.除非您绝对必须使用 Python 2,否则请安装 Python 3.x。

Next install or upgrade your Python's packaging tools .接下来安装或升级 Python 的打包工具 This is one of the very rare times that I install or upgrade packages in my Pythons, although you may want to do so for your user.这是我在 Python 中安装或升级包的极少数情况之一,尽管您可能希望为您的用户这样做。

Next create and use a virtual environment .接下来创建并使用一个虚拟环境

Finally follow the correct guide to install Sphinx into your virtual environment and get started using Sphinx.最后按照正确的指南将 Sphinx 安装到您的虚拟环境中并开始使用 Sphinx。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM