Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
What is the name of your python script? –  Sabacon Dec 25 '11 at 14:15
    
It was, but I renamed it to testpygments.py, still get ImportError. Thanks anyway :) –  umpirsky Dec 25 '11 at 14:16
    
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 '11 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 '11 at 14:25
add comment

2 Answers

up vote 2 down vote accepted

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"

share|improve this answer
add comment

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.

share|improve this answer
    
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 '11 at 13:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.