I get an ImportError: cannot import name bytes with pygments

2.5k views Asked by At

I wanted to get syntax highlighting for code plugin (https://ankiweb.net/shared/info/491274358) in Anki (https://ankiweb.net/) to be able to highlight ipython synthax.

I installed

pygments-ipython-console

from here: https://bitbucket.org/hplbit/pygments-ipython-console.git and installed according to the instruction given there.

Testing it, it seems to work:

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

My Pygments version is:

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

The error that occurs in Anki is the following:

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

Can anyone tell me about this error. Do I have to downgrade pygments?

1

There are 1 answers

0
Stephen Pascoe On BEST ANSWER

Version 1.6 of Pygments defined pygments.util.bytes in the Python 2/3 compatibility code but that is removed in version 2.1.

Therefore you should downgrade to 1.6 and file a bug report.

The util.py source: