1

I have a server running on Ubuntu 10.04 on which I wanted to install Mercurial via

% sudo apt-get install mercurial

It seems to have installed successfully and doesn't show me any error messages. But when I try it I get:

% hg
abort: couldn't find mercurial libraries in [/usr/bin /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/pymodules/python2.6 /usr/local/lib/python2.6/dist-packages]
(check your install and PYTHONPATH)

I've googled for a while now and found some sites with the same problem but I still have no idea on how to fix it since it nowhere really says what I need to look for or what I need to add to my PYTHONPATH...

By the way, right now my PYTHONPATH seems to be empty:

% echo $PYTHONPATH

%

This is what I get if I look into my /usr/lib/ directory for mercurial:

% find /usr/lib/py* -name 'mercurial*'
/usr/lib/pymodules/python2.6/mercurial
/usr/lib/pymodules/python2.6/mercurial-1.4.3.egg-info
/usr/lib/pyshared/python2.6/mercurial

Can anybody please help me with that? What (and how) should I set my PYTHONPATH to? I already tried reinstalling, installing with "easy_install mercurial" or with "aptitude reinstall mercurial" but nothing helped. I always get this same error.

Would be great if anyone could help... thanks!

ADDITION:

Building from scratch didn't work out well... when I am logged in as root I can use hg, but when I access with my normal user I get:

% hg
Traceback (most recent call last):
  File "/usr/local/bin/hg", line 4, in <module>
    import pkg_resources
  File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 2659, in <module>
    parse_requirements(__requires__), Environment()
  File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 546, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: mercurial==1.7.2
florianbaethge
  • 225
  • 1
  • 3
  • 8

6 Answers6

2

I'm not sure about the precise reason for this, but I've worked around a similar problem by installing Mercurial from source (you may want to remove any Mercurial packages first, though).

Download the Mercurial tarball here and extract it:

  tar tvf mercurial-1.7.5.tar.gz
  cd mercurial-1.7.5
  python setup.py install

...this should do it. If you have several versions of python installed (2.5, 2.6, 2.7), use the latest one.

lubomir.brindza
  • 256
  • 3
  • 10
  • thanks for the advice... I've just tried, but it fails since some python headers are missing... what do I need to install for this to work? The result is added to your post (visible as soon as it's reviewed) – florianbaethge Feb 12 '11 at 14:15
  • Nevermind! I got it myself... I installed "python2.6-dev" and it successfully compiled... mercurial is now working!!! Thank you for your help! – florianbaethge Feb 12 '11 at 14:18
  • So now the OP looses all the benefits of a repo? Installing from source may of fixed the problem but it has a ton of disadvantages – TheLQ Feb 12 '11 at 15:17
  • I don't claim to have a solution, just a workaround. I'm partial to instant gratification. Also, could you specify the benefits lost (other than the package being about a year behind the current stable version)? – lubomir.brindza Feb 12 '11 at 15:27
  • unfortunately I found out that this didn't work as it should... :( While installing I was logged in as root, but if I go in with my normal user I cannot use hg. I get this error:% hg Traceback (most recent call last): File "/usr/local/bin/hg", line 4, in import pkg_resources File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 2659, in parse_requirements(__requires__), Environment() File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 546, in resolve raise DistributionNotFound(req) pkg_resources.DistributionNotFound: mercurial==1.7.2 – florianbaethge Feb 12 '11 at 21:11
  • Did you install Mercurial 1.7.2 at all (the version I linked was 1.7.5)? I guess my first impulse would be to `grep -r "1\.7\.2"` in python libraries directory and see what it turned out. I have a VM with Ubuntu 10, will try to reproduce the issue there. – lubomir.brindza Feb 13 '11 at 08:00
  • no I didn't... I just downloaded the 1.7.5 that was linked here... – florianbaethge Feb 13 '11 at 13:39
  • Well it seems like root uses a 1.7.2 install... no idea where this comes from: % sudo hg --version Mercurial Distributed SCM (version 1.7.2) – florianbaethge Feb 13 '11 at 14:21
1

Something like this happened to me in OS X when I gave the system Python first priority over the version of python I had installed with Homebrew. I should have prepended the Homebrew version to PATH instead of postpending it. More info at https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python.

So in .bash_profile or the similar rc file, I changed the order of

PATH=/usr/local/share/python:"${PATH}"
PATH=/usr/local/bin:"${PATH}"

to

PATH=/usr/local/bin:"${PATH}"
PATH=/usr/local/share/python:"${PATH}"

and then Mercurial stopped throwing that error.

orluke
  • 111
  • 1
1

(I hope vou've solved this by now, but I'll try giving some advice about how to find Mercurial anyway.)

First: please come to the IRC channel if you run into this kind of problem. That's much better than trying random things to make it work — installing things here and there will only make you and your system more confused :-)

It sounds like you've tried many different things to install Mercurial. Be very careful with mixing different ways of installing Mercurial (or any other Python program, for that matter). The second error you get is because you're starting one version of Mercurial (version 1.7.2) and it's finding older libraries. So you've probably got two more or less working installations by now.

So my advice would be to remove the Ubuntu package and remove any other versions of Mercurial. Search for directories and files called mercurial and delete them (but delete the package first, of course).

Then install the package — if the version in Ubuntu's normal repository is too old, then use the Mercurial PPA. The first error you got means that Mercurial cannot find it's libraries (this is of course strange and unexpected when you install Mercurial from an Ubuntu package). Try running

$ python -c 'import mercurial; print mercurial'

to see if you can import the mercurial package yourself. If that works, then you'll see where the package lives and you can add the parent directory to your PYTHONPATH:

$ PYTHONPATH=/usr/lib/python2.7/dist-packages/ hg debuginstall

If that doesn't work, then search for commands.py. That is a file in Mercurial and the grand-parent directory of that file should be on your PYTHONPATH.

That should get you up and running... but, again, it's not expected that you have to fiddle with this yourself when you install Mercurial using a package manager.

Martin Geisler
  • 1,271
  • 9
  • 23
1

I had exactly the same issue and this is what seemed got it working (could be that there was something else which i did but I cant recall now):

sudo apt-get install mercurial

sudo apt-get install --reinstall python-software-properties && sudo dpkg-reconfigure python-software-properties
alexeit
  • 906
  • 2
  • 16
  • 18
1

Just add the Mercurial lib Path to PYTHONPATH.

  1. Locate the libraries: locate mercurial, and find the Lib PATH. E.g. /usr/lib64/python2.6/site-packages/mercurial ;
  2. Add the Lib Path to PYTHONPATH: export PYTHONPATH=$PYTHONPATH:/usr/lib64/python2.6/site-packages.

The Lib path may be a different place in your machine. And you could permanently add the export sentence to ~/.bashrc or ~/.zshrc .

Leo Bian
  • 11
  • 1
0

I was getting this error as well, and reinstalling, removing/installing didn't help. It turned out that my system had Python2.3 and Python2.4 installed. It was using Python2.4, but the mercurial libraries were installed in Python2.3. I copied the mercurial libraries to Python2.4, and it fixed the problem. Here are the commands I used to copy the libraries:

cd /usr/lib64/python2.4/site-packages sudo cp -r /usr/lib64/python2.3/site-packages/mercurial .

Mel
  • 1
  • Unfortunately this does not seem to cover what the OP is asking. He has a copy of the libraries for Python 2.6, but it looked more like Debian's Python infrastructure did not copy or link them to the correct place. – pino42 Nov 14 '12 at 00:22