It’s been a while since I had this problem with mercurial in Archlinux, and now was time to fix it.

Before I started using virtualenv months ago, I did all my experiments in the Archlinux root for Python2.7, it seems it(or I) broke something in a compilation and it affected Mercurial build for my system. I couldn’t even clone a mercurial repository, it always threw this interesting error…

    Traceback (most recent call last):
  File "/usr/bin/hg", line 36, in <module>
    mercurial.util.setbinary(fp)
  File "/usr/lib/python2.7/site-packages/mercurial/demandimport.py", line 86, in __getattribute__
    self._load()
  File "/usr/lib/python2.7/site-packages/mercurial/demandimport.py", line 58, in _load
    mod = _origimport(head, globals, locals)
  File "/usr/lib/python2.7/site-packages/mercurial/util.py", line 202, in <module>
    collections.deque.remove
  File "/usr/lib/python2.7/site-packages/mercurial/demandimport.py", line 86, in __getattribute__
    self._load()
  File "/usr/lib/python2.7/site-packages/mercurial/demandimport.py", line 58, in _load
    mod = _origimport(head, globals, locals)
  File "/usr/lib/python2.7/collections.py", line 9, in <module>
    from operator import itemgetter as _itemgetter
  File "/usr/lib/python2.7/site-packages/mercurial/demandimport.py", line 114, in _demandimport
    mod = _origimport(name, globals, locals)
ImportError: /usr/lib/python2.7/site-packages/operator.so: undefined symbol: _PyUnicodeUCS2_AsDefaultEncodedString

I tried to fix it compiling python with --enable-unicode=ucs4, but didn’t work. After an hour trying to fix this in /usr/lib, I realised I could try to fix it in a virtualenv, it’s a great way to have everything under control in any of your python projects and I’ve been using it for every project.

My final solution was as easy as…

$ virtualenv2 ~/.virtualenvs/mercurial
$ workon mercurial # Or ~/.virtualenvs/mercurial/bin/activate
$ cd Mercurial-3ee5d3c372fa/ # tarball from http://selenic.com/hg/file/3ee5d3c372fa
$ python setup.py install

That’s it! it runs smoothly now.

UPDATE: Once I could isolate the problem I realised it had to be with some kind of problem with an import for SSL, I moved the operator.so file and installed the Mercurial tarball I downloaded previously in my virtualenv (and worked there), I think the problem is solved now, It seemed a compilation build was done in a wrong place. :-)