Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

'_pygments_highlight' is not defined #19

Closed
dreamalligator opened this issue Nov 29, 2014 · 1 comment
Closed

'_pygments_highlight' is not defined #19

dreamalligator opened this issue Nov 29, 2014 · 1 comment

Comments

@dreamalligator
Copy link

Hi, I have Pygments installed, but get an error

WARNING: Could not process ./2014-11-29-test-notebook.ipynb
global name '_pygments_highlight' is not defined

Updates:

You can duplicate this in IPython, using the line #27 in ipynb.py

In [2]: from IPython.nbconvert.filters.highlight import _pygments_highlight
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-703783dd7ab9> in <module>()
----> 1 from IPython.nbconvert.filters.highlight import _pygments_highlight

ImportError: cannot import name _pygments_highlight

Woops, looks like I have an aged IPython version.

ipython -V
1.2.1

Although I checked running from IPython.nbconvert.filters.highlight import _pygment_highlight in IPython and it doesn't error. This is for the IPython version > 2.0. Why would it fail inside of the ipynb plugin and not IPython notebook?

Ran pip install ipython[all] too.

I downloaded the newest release on Github, tar xvfz ipython-2.1.0.tar.gz, cd ipython-2.1.0/, python setup.py install, and it didn't fix. I double-checked by uninstalling pip uninstall ipython. Confirmed it was gone, then reran python setup.py install, and it returns 1.2.1 instead of 2.1.0. Maybe IPython didnt update their internal version number with the release?

Anyway, besides a version number issue that may be unrelated, I don't see why the try from IPython.nbconvert.filters.highlight import _pygment_highlight would fail when I can run it in IPython?

@dreamalligator
Copy link
Author

Okay, I was being silly about the version number stuff, there were conflicting IPython versions. I solved that with apt-get remove ipython. So, with version 2.1.0.

try:
    from IPython.nbconvert.filters.highlight import _pygment_highlight
except ImportError:
    # IPython < 2.0
    from IPython.nbconvert.filters.highlight import _pygments_highlight

And the earlier import wasnt the issue, maybe instead of _pygments I needed output = _pygment_highlight(source, formatter, language, metadata) in the custom_highlighter method. but now with the correct version, things work a-okay.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant