【问题标题】:I get an ImportError: cannot import name bytes with pygments我得到一个 ImportError: cannot import name bytes with pygments
【发布时间】:2023-03-26 17:54:01
【问题描述】:

我想在 Anki (https://ankiweb.net/) 中获得代码插件 (https://ankiweb.net/shared/info/491274358) 的语法高亮,以便能够高亮 ipython synthax。

我安装了

pygments-ipython-控制台

从这里:https://bitbucket.org/hplbit/pygments-ipython-console.git 并根据那里给出的说明进行安装。

测试了一下,好像可以了:

$ pygmentize -L lexer | grep -i ipy
* ipy:
    IPy session (filenames *.ipy)

我的 Pygments 版本是:

$ pygmentize -V
Pygments version 2.0.1, (c) 2006-2014 by Georg Brandl.

Anki中出现的错误如下:

Traceback (most recent call last):
  File "/usr/share/anki/aqt/addons.py", line 39, in loadAddons
    __import__(file.replace(".py", ""))
  File "/home/chriad/Documents/Anki/addons/Syntax Highlighting for Code.py", line 2, in <module>
    import code_highlight_addon.code_highlight_addon
  File "/home/chriad/Documents/Anki/addons/code_highlight_addon/code_highlight_addon.py", line 201, in <module>
    from pygments.lexers import get_lexer_by_name, get_all_lexers
  File "/home/chriad/Documents/Anki/addons/code_highlight_addon/pygments/lexers/__init__.py", line 19, in <module>
    from pygments.util import ClassNotFound, bytes
ImportError: cannot import name bytes

谁能告诉我这个错误。我必须降级 pygments 吗?

【问题讨论】:

    标签: ipython pygments anki


    【解决方案1】:

    1.6 版 Pygments 在 Python 2/3 兼容性代码中定义了 pygments.util.bytes,但在 2.1 版中被删除。

    因此,您应该降级到 1.6 并提交错误报告。

    util.py 来源:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-20
      • 2016-05-16
      • 2018-10-27
      • 2020-07-16
      • 2019-06-10
      相关资源
      最近更新 更多