【问题标题】:Errors when attempting to run Sphinx on some GIMP Python Plugin code尝试在某些 GIMP Python 插件代码上运行 Sphinx 时出错
【发布时间】:2019-09-24 12:51:32
【问题描述】:

我正在尝试使用 Sphinx 来记录 Python 文件,该文件用于实现 GIMP 插件。问题是,当我跑步时;

make html

我收到以下消息 - 如下所示,产生错误;

sphinx-build -b html -d _build/doctrees   . _build/html
Running Sphinx v2.2.0
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] code                                                                                                                        
WARNING: autodoc: failed to import module 'Plugin_ImageOverlay'; the following exception was raised:
Traceback (most recent call last):
  File "/home/craig/.local/lib/python3.5/site-packages/sphinx/ext/autodoc/importer.py", line 32, in import_module
    return importlib.import_module(modname)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/craig/.gimp-2.8/plug-ins/ImageOverlay/Plugin_ImageOverlay.py", line 73, in 
  <module>
    from   gimpfu import register, main, pdb, gimp, PF_IMAGE, PF_DRAWABLE, PF_INT, 
    PF_STRING, PF_FILE, PF_BOOL, INTERPOLATION_NONE, INTERPOLATION_LINEAR, 
    INTERPOLATION_CUBIC, INTERPOLATION_LANCZOS, PF_RADIO
  File "/usr/lib/gimp/2.0/python/gimpfu.py", line 235
    raise error, "parameter name contains illegal characters"
               ^
SyntaxError: invalid syntax

looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index                                                                                                                        
generating indices...  genindexdone
writing additional pages...  search/home/craig/.local/lib/python3.5/site-
packages/sphinx_rtd_theme/search.html:20: RemovedInSphinx30Warning: To modify script_files 
in the theme is deprecated. Please insert a <script> tag directly in your theme instead.
{{ super() }}
done
copying static files... ... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded, 1 warning.

The HTML pages are in _build/html.

Build finished. The HTML pages are in _build/html.

如果从上面的输出中看不出来,则显示错误消息;

  File "/usr/lib/gimp/2.0/python/gimpfu.py", line 235
    raise error, "parameter name contains tllegal characters"
               ^
SyntaxError: invalid syntax

我不太了解 Python 或 Sphinx,但这个错误是否与 Python 版本 2 和 3 之间的语法差异有关? GIMP 可以毫无问题地加载和执行我的插件 - 那么为什么 Sphinx 似乎会卡住它呢?

是否有一些我不知道的简单解决方法,例如可以放在 Sphinx 的 conf.py 文件中的键值对?

提前感谢您的帮助。

【问题讨论】:

标签: python python-3.x python-sphinx gimp gimpfu


【解决方案1】:

您使用的是 Sphinx 2.2.0 版,Sphinx dropped support for Python 2 since 2.0.x

gimpfu.py 中的raise error, e 样式是not supported in Python 3.x。 (你应该使用raise error(e)

您可以尝试使用支持 Python 2 的旧版 Sphinx,或者破解 gimp 以使用与 Python 3 兼容的语法,或者要求 gimp 人员修复它...

【讨论】:

  • 或者可能让 Sphynx 忽略/排除 Gimp 的东西。
  • 我尝试通过注释掉相关的 Python from ... import ... 语句来从 Sphinx 隐藏 gimpfu 模块。所有这一切都在源代码文件的下方产生了其他问题。我开始编辑 gimpfu.py 文件时,我想我应该先停下来问一个关于它的问题,在 Stack Overflow 上。我认为也许 Sphinx 可能有一个设置,例如 use_python_major_version = '2',我可以在项目的 conf.py 文件中启用它。感谢您提供所有有用的反馈。
猜你喜欢
  • 2014-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-05
  • 2019-08-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多