3

I want tot use pygments in my python app.

At first, I installed pygments like this:

$sudo python setup.py install --prefix=/usr/local
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'zip_safe'
  warnings.warn(msg)
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'include_package_data'
  warnings.warn(msg)
running install
running build
running build_py
running build_scripts
running install_lib
running install_scripts
changing mode of /usr/local/bin/pygmentize to 755
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/Pygments-1.4-py2.7.egg-info
Writing /usr/local/lib/python2.7/dist-packages/Pygments-1.4-py2.7.egg-info

After getting import error (ImportError: cannot import name highlight ) when trying to from pygments import highlight, and find out that there is a python-pygments package, I installed it from software center. Now it was installed in /usr/share/pyshared/pygments and there are symlinks in /usr/lib/python2.7/dist-packages/pygments point to that location which is much better then /usr/local/lib/python2.7/dist-packages with manual install.

But I keep getting ImportError.

What am I doing wrong?

4
  • 1
    What is the name of your python script?
    – Sabacon
    Dec 25, 2011 at 14:15
  • It was, but I renamed it to testpygments.py, still get ImportError. Thanks anyway :)
    – umpirsky
    Dec 25, 2011 at 14:16
  • 1
    Ok sometimes running a python script leave a compiled version of the script in the folder the script was run from, if so delete the pygments.pyc file and try again
    – Sabacon
    Dec 25, 2011 at 14:19
  • Ah, that's right, after deleting pygments.pyc it works! Man, this is nut's, I'm running python testpygments.py, why is pygments.pyc throwing error? Thanks a bunch.
    – umpirsky
    Dec 25, 2011 at 14:25

2 Answers 2

4

Do not name your script "pygments.py". Secondly if you did the above and consequently change the name of the script, you may still get an import error caused by the Byte-compiled python script called "pygments.pyc", you will need to change the name of the script and delete the old byte-compiled script called "pygments.pyc"

1

pigments is packaged in Ubuntu: http://packages.ubuntu.com/search?keywords=python-pygments

I suggest you use that package rather than installing from upstream source.

1
  • Thanks for quick response. Please read question carefully " and find out that there is a python-pygments package, I installed it from software center. Now it was installed in /usr/share/pyshared/pygments and there are symlinks in /usr/lib/python2.7/dist-packages/pygments point to that location which is much better then /usr/local/lib/python2.7/dist-packages with manual install. But I keep getting ImportError.".
    – umpirsky
    Dec 25, 2011 at 13:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .