Different behavior when Pygments run in script from $PATH vs local directory.

Issue #1354 new
Anonymous created an issue

Hi there,

I'm not sure if this is a bug or if it's operator error, but it seems like inexplicable behavior to me... but nobody on Stack Overflow seems to have any ideas, so I assume this isn't widely-known behavior. Please shout at me only gently if it turns out to be an intended limitation. :-)

But I have a trivial json pretty-printing python script that uses Pygments. Here's the entire thing.

#!/usr/bin/env python
import json, sys
from pygments import highlight
from pygments.lexers.data import JsonLexer
from pygments.formatters import TerminalFormatter

with open(sys.argv[1]) as dj:
    data = json.dumps(json.load(dj), indent=4, sort_keys=True)

print(highlight(data, JsonLexer(), TerminalFormatter()))

Like I said, trivial.

Here's the weird thing. Pygments highlighting works when this script is located in the same directory as the json file it's called with. But Pygments highlighting does not work when the script is located elsewhere, on the $PATH. No error is thrown (so the interpreter is obviously able to import the library), and the json indentation and such works right---the colors just don't appear.

Just for experimental purposes, I rewrote the script using the clojure wrapper for pygments. And that works fine from $PATH.

Anyway, I imagine this is a bug...


  • I'm not using any virtualenv.

  • Python 2.7.

  • My shell is ZSH, on a Mac, via iterm2.

Comments (1)

  1. Log in to comment