Skip to content Skip to sidebar Skip to footer

Python Import Seems To Behave Differently In Mercurial_keyring.py File

A bizarre import error is preventing me from installing a mercurial extension. I'm trying to get the mercurial_keyring extension running so that I don't have to type in my user nam

Solution 1:

Most likely, hg is running using the system python (2.6) rather than the copy of 2.7 you have installed.

Try installing mercurial_keyring and keyring under 2.6, and see if that gets things working as expected.

Solution 2:

Mercurial uses a feature called 'demandimport' which postpones the import of modules, until the first time they are used. So, your

import keyring

won't fail at that line, but it will wail only when it's used first(i.e)

return keyring.get_password(...)

Solution 3:

I encountered the same issue and resolved it by installing extension with easy install: sudo easy_install mercurial_keyring

This installs it under the same python that mercurial uses.

Solution 4:

@ncoghlan's answer is right (for me, anyway), but incomplete and I don't have enough rep points to comment. (Jeremy S, I think this answers your question.)

To install for a specific version of Python, use the following modifications: Instead of

easy_install keyring

Use

easy_install-2.6 keyring

Same applies for any of the easy_install or other Python commands. I found this from an example for pip here: How to install a module use pip for specific version of?

Solution 5:

imports in methods are evaluated when they're called, whereas top-level imports are evaluated immediately. The behavior of imports can be modified, have a look at the imp and site modules as well as sys.path. What is probably happening is that some code at the end of the file (figuratively, may also be a function call on initialization or so) modifies the import behavior by accident or to prevent and notice inadvertent late imports.

Post a Comment for "Python Import Seems To Behave Differently In Mercurial_keyring.py File"