demandimport error - *** failed to import extension mercurial_keyring: 'module' object has no attribute 'system'

Create issue
Issue #31 wontfix
Matt Joiner created an issue
matt@netbook:~/src/go/src$ pip list | grep keyring
keyring (3.0.1)
mercurial-keyring (0.6.0)
matt@netbook:~/src/go/src$ python2 -c 'import mercurial.demandimport as d; d.enable(); import mercurial_keyring; from mercurial_keyring import PasswordStore'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/mercurial/", line 114, in _demandimport
    mod = _origimport(name, globals, locals)
  File "/usr/local/lib/python2.7/dist-packages/", line 82, in <module>
    import keyring
  File "/usr/lib/python2.7/dist-packages/mercurial/", line 95, in _demandimport
    return _import(name, globals, locals, fromlist, level)
  File "/usr/local/lib/python2.7/dist-packages/keyring/", line 12, in <module>
    from .core import (set_keyring, get_keyring, set_password, get_password,
  File "/usr/lib/python2.7/dist-packages/mercurial/", line 112, in _demandimport
    return _origimport(name, globals, locals, fromlist, level)
  File "/usr/local/lib/python2.7/dist-packages/keyring/", line 166, in <module>
  File "/usr/local/lib/python2.7/dist-packages/keyring/", line 58, in init_backend
    keyring = load_config()
  File "/usr/local/lib/python2.7/dist-packages/keyring/", line 127, in load_config
    config_path = os.path.join(platform.data_root(), filename)
  File "/usr/lib/python2.7/dist-packages/mercurial/", line 86, in __getattribute__
  File "/usr/lib/python2.7/dist-packages/mercurial/", line 58, in _load
    mod = _origimport(head, globals, locals)
  File "/usr/local/lib/python2.7/dist-packages/keyring/util/", line 24, in <module>
    data_root = globals().get('_data_root_' + platform.system(), _data_root_Linux)
  File "/usr/lib/python2.7/dist-packages/mercurial/", line 87, in __getattribute__
    return getattr(self._module, attr)
AttributeError: 'module' object has no attribute 'system'
matt@netbook:~/src/go/src$ uname -a
Linux netbook 3.8.0-29-generic #42-Ubuntu SMP Tue Aug 13 19:40:39 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
matt@netbook:~/src/go/src$ hg version
*** failed to import extension mercurial_keyring: 'module' object has no attribute 'system'
Mercurial Distributed SCM (version 2.2.2)

Comments (22)

  1. Matt Joiner reporter

    Thanks for following this up @jaraco ! I take it then if the fix belongs in Mercurial (of which I'm using 2.2), this is not likely to arrive in a point release for 2.2 in the short term, if at all?

  2. Jason R. Coombs

    We can probably fix this in keyring, but I do want to get a feel for how things will go upstream first. Before your comment, My feeling was that the issue emerged recently in keyring so was due to early adoption of keyring which would suggest the likelihood of early adoption of Mercurial updates as well.

    Since that's not the case, and that's surely not a reason not to address the issue, would you be willing to share a bit more about your environment and why updating keyring is important but why you stick to older versions of Mercurial? I ask for my edification and curiosity more than anything.

  3. Matt Joiner reporter

    I don't believe mercurial_keyring or keyring are packaged in Ubuntu 13.04. This is all. I stick to the system packaged versions of Mercurial because I use several Mercurial tools that rely on the system version.

  4. Matt Joiner reporter

    You may be interested to know that the next release of Ubuntu, has decided to package mercurial_keyring 0.5.6, probably for the same reasons I have to try to use this version. Unfortunately it's not available via pip anymore.

  5. Matt Joiner reporter

    Sorry, I mean the problem doesn't exist with 3.0.3. I don't get the titular error message.

  6. Marcin Kasperski repo owner

    If you take a look at the list of past issues in mercurial_keyring, you may note that most of them are similar to this one: keyring itself or some keyring backend imports some library, mercurial's demandimport fires and destroys import, I get the error.

    Then I am to guess what to blacklist so demandimport stops spoiling things (and I usually don't have backend in charge installed or even OS on which the problem happens, so I can't test anything).

    I must say I have enough.

    I won't guess anymore. I gladly accept patches which extend those demandimport blacklists, I promise to quickly number and distribute releases, but I am fed up with discussions like „try blacklisting this and this. DId not help? Well, maybe try that? ...”

    Do you want this bug fixed? Open the source here: , try adding things to blacklist until mercurial stops spoiling things, then offer me pull request.

    Or maybe persuade mercurial authors that this demandimport idea isn't so great, they saved an hour or two thanks to not writing "from mercurial import something" lines, people who extend mercurial spend time facing issues as this one.

  7. Jason R. Coombs

    Hi Marcin. I value your time and respect your pain. For this issue and related ones, I've taken in late versions of keyring to explicitly force imports by accessing a module attribute early, so these issues should be minimized in the future.

    But I agree - it's absolutely not fair to you to ask you to guess at blacklists. And yes, the demandimport idea is annoying, but my understanding is it's a necessary pain for mercurial to have reasonable startup performance.

  8. Marcin Kasperski repo owner

    If anyone still faces it, it would be much better to check what must be blacklisted (as sooner or later next person is to face the same library versions combination). As I said, I am OK with accepting those blacklisting changes, I just don't want to guess myself.

  9. Katsunori FUJIWARA

    The patch to fix root cause of this issue is imported into main repository of Mercurial itself.

    2.8-rc or later releases should include this fix.

  10. Franck Bret

    I had the same issue on Ubuntu 13.10 while installing the packaged deb that install mercurial-keyring 0.5.5. Just force the python package upgrade with "sudo pip install mercurial_keyring --upgrade" It will install 0.6.1 and solve that issue

  11. Marcin Kasperski repo owner

    As nobody suggested specific things to blacklist, and I have nothing to add here, I close the issue.

  12. Log in to comment