【发布时间】:2017-07-03 19:48:43
【问题描述】:
我正在使用 sphinx python 库生成文档,我遇到了
can not import normalize 错误。
我找到了 2014 年的 similar question,但它并没有解决我的问题。
测试代码
# hello.py
def myadd(a,b):
"""
Parameters
----------
a: first parameter
b: second paramter
Returns
-------
Return: Sum of two arguments
"""
return a+b
if __name__=="__main__":
a = myadd(5,6)
print('\n')
print(a)
Sphinx 和语言环境安装
import sphinx
from locale import normalize # I got no error here
print(sphinx.__version__) # 1.6.2
Sphinx 命令
sphinx-quickstart
> Project name: a
> Author name(s): a
> Create Makefile? (y/n) [y]:
> Create Windows command file? (y/n) [y]: n
this creates THREE files and THREE folders.
Then,
make html # this gives the error.
此过程适用于this youtube video。
但是,如果我重复相同的过程,我会收到以下错误:
File "/usr/lib/python2.7/gettext.py", line 440, in find
for nelang in _expand_lang(lang):
File "/usr/lib/python2.7/gettext.py", line 133, in _expand_lang
from locale import normalize
ImportError: cannot import name normalize
Makefile:20: recipe for target 'html' failed
make: *** [html] Error 1
有趣的是,当我从 locale 导入 normalize 时,我没有收到任何错误,而且 只有 sphinx 给出了这个错误。
问题
如何避免导入错误,使用 sphinx 生成文档?
我们将不胜感激!
相关链接
http://www.sphinx-doc.org/en/stable/tutorial.html
http://www.sphinx-doc.org/en/stable/ext/example_google.html
https://thomas-cokelaer.info/tutorials/sphinx/docstring_python.html
http://gisellezeno.com/tutorials/sphinx-for-python-documentation.html
【问题讨论】:
-
您的项目中是否有名为“locale”或“locale.py”的文件或文件夹?见stackoverflow.com/a/10875148/407651
-
@mzjn 不是真的,没有任何 locale.py。该项目只有一个文件HELLO.PY
-
我不知道如何重现这个。如果可能,请提供minimal reproducible example。
-
@mzjn,我也没有,现在我正在 MAVERICKS 中测试 make html,它没有给我带来任何问题。但是在我的 MacbookPro 笔记本电脑中,它有 Sierra OS,它内置了 python2,我已经安装了 anaconda python3.6。我遇到了问题。
-
@mzjn,不需要 MWE,对我来说,Sierra OS 中的所有 python 脚本“制作 html”都失败了。
标签: python python-sphinx importerror