Lets say I'm in a file called openid.py
and I do :
from openid.consumer.discover import discover, DiscoveryFailure
I have the openid
module on my pythonpath but the interpreter seems to be trying to use my openid.py
file. How can I get the library version?
(Of course, something other than the obvious 'rename your file' answer would be nice).
This is not possible with the pip. All of the packages on PyPI have unique names. Packages often require and depend on each other, and assume the name will not change. Even if you manage to put the code on Python path, when importing a module, python searches the paths in sys.
You need to use the import keyword along with the desired module name. When interpreter comes across an import statement, it imports the module to your current program. You can use the functions inside a module by using a dot(.) operator along with the module name.
Relative imports make use of dot notation to specify location. A single dot means that the module or package referenced is in the same directory as the current location. Two dots mean that it is in the parent directory of the current location—that is, the directory above.
Python looks for modules in “sys. It looks for a file called a_module.py in the directories listed in the variable sys. path .
Thats the reason absolute imports have been chosen as the new default behaviour. However, they are not yet the default in 2.6 (maybe in 2.7...). You can get their behaviour now by importing them from the future:
from __future__ import absolute_import
You can find out more about this in the PEP metnioned by Nick or (easier to understand, I think) in the document "What's New in Python 2.5".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With