6

When trying to launch Mercurial(hg) after a restart in my Ubuntu 9.10 Linux Box I got following message:

      abort: couldn't find mercurial libraries in [/usr/bin /usr/local/lib/python2.6/dist-packages/vipy-0.4-py2.6.egg /usr/local/lib/python2.6/dist-packages/nose-0.11.1-py2.6.egg /usr/local/lib/python2.6/dist-packages/rope-0.9.2-py2.6.egg /usr/local/lib/python2.6/dist-packages/Sphinx-0.6.3-py2.6.egg /usr/local/lib/python2.6/dist-packages/django_html-0.0.1-py2.6.egg /usr/local/lib/python2.6/dist-packages/html5lib-0.11.1-py2.6.egg /home/kenny /home/kenny/Projects/soclone-read-only /home/kenny/python/Django /home/kenny/python/pysmell /home/kenny/python/Django/ropemode /home/kenny/python/Django/rope /home/kenny/python/lib /usr/lib/python2.6 /usr/lib/python2.6/plat-linux2 /usr/lib/python2.6/lib-tk /usr/lib/python2.6/lib-old /usr/lib/python2.6/lib-dynload /usr/local/lib/python2.6/dist-packages]

      (check your install and PYTHONPATH)

Mysteriously other Python programs don't find their modules, including django-admin, bzr, BUT surprisingly the Python interpreter itself is launching.

Here you can find my current sys.path:

  ['', '/usr/local/lib/python2.6/dist-packages/vipy-0.4-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/nose-0.11.1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/rope-0.9.2-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/Sphinx-0.6.3-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/django_html-0.0.1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/html5lib-0.11.1-py2.6.egg', '/home/kenny', '/home/kenny/Projects/soclone-read-only', '/home/kenny/python/Django', '/home/kenny/python/pysmell', '/home/kenny/python/Django/ropemode', '/home/kenny/python/Django/rope', '/home/kenny/python/lib', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/local/lib/python2.6/dist-packages']

Does anyone know how to resolve this issue?

I know this is no programming question in specific, but it disallows me to program, so I beg your comprehension!

Thanks in advance.

Kenny Meyer
  • 7,849
  • 6
  • 45
  • 66
  • Please include the error message in your question, if the pastebin is ever removed, your question loses its context. – John Paulett Dec 04 '09 at 14:30
  • How did you install mercurial? Was it throught apt-get/aptitude or from the tar.gz source? – John Paulett Dec 04 '09 at 14:33
  • I installed it through apt-get and it was running before... It's not only mercurial, which is not running, rather *all* python programs with libraries in /usr/ are affected... Python raises an import error. And I have been running this system now 2 months without this issue. As I said.. after a restart I encountered this problem. – Kenny Meyer Dec 04 '09 at 14:38

5 Answers5

8

Try this:

update-python-modules -p

(might need to sudo that...) Source: http://hg.opensource.lshift.net/mercurial-server/rev/32dba1a70a54

Rolf
  • 96
  • 1
  • 1
  • 1
    It did it for me, but for mercurial-server. Mercurial was exhibiting the exact same problem, though. I replaced it with mercurial-server so I didn't test on mercurial. Hope that makes sense. – Rolf Oct 13 '11 at 23:19
  • Sorry mate, but I cannot reproduce the original error as I got a new life in the two years since I've posted the thread. I hope your answer might be useful to someone else, though. – Kenny Meyer Oct 14 '11 at 00:18
  • that is working solution for me on Debian 6 32-bit. Thanks a lot! – ramusus Jan 17 '12 at 08:41
  • Worked for me as well. I did install some packages with pip and easy_install before my python path ended up being corrupted. – Tolsto Feb 22 '14 at 19:35
5

All of the sites I've googled for this say that your PYTHONPATHis set wrong. The code that you are hitting in mercurial appears to be this:

try:
    from mercurial import demandimport; demandimport.enable()
except ImportError:
    import sys
    sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" %
                     ' '.join(sys.path))
    sys.stderr.write("(check your install and PYTHONPATH)\n")
    sys.exit(-1)

So where is demandimport on your machine? On my windows box, it is here:

>>> from mercurial import demandimport
>>> demandimport.__file__
'C:\\Python26\\lib\\site-packages\\mercurial-1.4.1-py2.6-win32.egg\\mercurial\\demandimport.pyc'

And that works because I have mercurial in my PYTHONPATH:

>>> import sys
>>> for s in sys.path:
...     print s
...
# Other crud deleted...
C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg
C:\Windows\system32\python26.zip
C:\Python26\DLLs
C:\Python26\lib
C:\Python26\lib\plat-win
C:\Python26\lib\lib-tk
C:\Python26
C:\Python26\lib\site-packages

Your PYTHONPATH makes no mention of mercurial. At a guess, I would add this to your PYTHONPATH:

/usr/local/lib/python2.6/site-packages

and I would re-install mercurial from make. That advice worked well here.

Edit: And on my Ubuntu 9.10 box, I got these results:

>>> import mercurial
>>> mercurial.__file__
'/usr/lib/pymodules/python2.6/mercurial/__init__.pyc'
>>> import sys
>>> for s in sys.path:
...     print s
...

/usr/local/lib/python2.6/dist-packages/pip-0.6.1-py2.6.egg
/usr/local/lib/python2.6/dist-packages/virtualenv-1.4.3-py2.6.egg
/usr/lib/python2.6
/usr/lib/python2.6/plat-linux2
/usr/lib/python2.6/lib-tk
/usr/lib/python2.6/lib-old
/usr/lib/python2.6/lib-dynload
/usr/lib/python2.6/dist-packages
/usr/lib/python2.6/dist-packages/PIL
/usr/lib/python2.6/dist-packages/gst-0.10
/usr/lib/pymodules/python2.6
/usr/lib/python2.6/dist-packages/gtk-2.0
/usr/lib/pymodules/python2.6/gtk-2.0
/usr/local/lib/python2.6/dist-packages
/usr/local/lib/python2.6/dist-packages/PIL

And this makes me think the problem is that this is missing for you: /usr/lib/pymodules/python2.6.

hughdbrown
  • 47,733
  • 20
  • 85
  • 108
1

Is mercurial located in one of the library installation paths (dist-packages or site-packages)? You can use the find tool to look for it?

Did you have luck installing small libraries and access them from Python on this machine?

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
  • A search with find (find /usr/ -name mercurial -type d) gives me the following: ./lib/pyshared/python2.5/mercurial ./lib/pyshared/python2.6/mercurial ./lib/pymodules/python2.6/mercurial ./share/mercurial ./share/pyshared/mercurial If you mean with small libraries, libraries from my ~/python/, then yes, I *can* import them :) . Also essential modules like sys, os, io, all no problem. Most of my libraries are located in /usr/lib/pymodules , but adding this path to $PYTHONPATH after restarting the shell, doesn't solve the problem. Thanks for your effort.! – Kenny Meyer Dec 04 '09 at 14:49
  • Try `/usr/lib/pymodules/python2.6`. – hughdbrown Dec 04 '09 at 16:02
1

Thanks for the effort to all of you.

I've solved the problem thanks to hughdbrown. hughdbrown, you've made me realize that I commited a typo when defining doing $PYTHONPATH; instead of adding the path /usr/lib/pymodules/python2.6, I wrote /usr/lib/pymodules/ so python couldn't import the libraries... However, I corrected it and I'm glad to see Mercurial and Co. work again.

The only strange thing is, WHY it changed... Well, I'll be knowing from now on what to do.

Kenny Meyer
  • 7,849
  • 6
  • 45
  • 66
0

You could try to reinstall affected Python programs with aptitude:

sudo aptitude reinstall mercurial
John Paulett
  • 15,596
  • 4
  • 45
  • 38