views:

148

answers:

1

Very strange for me:

# uname -a
Linux localhost.localdomain 2.6.18-194.3.1.el5 #1 SMP Thu May 13 13:09:10 EDT 2010 i686 i686 i386 GNU/Linux
# pwd
/root
# python
Python 2.6.5 (r265:79063, Apr 11 2010, 22:34:44)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dns
>>>
[3]+  Stopped                 python
# cd /home/user/dev/dns
[root@localhost dns]# python
Python 2.6.5 (r265:79063, Apr 11 2010, 22:34:44)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dns
Traceback (most recent call last):
  File "", line 1, in 
  File "dns.py", line 1, in 
    import dns.resolver
ImportError: No module named resolver
>>>
[4]+  Stopped                 python
#

Summary: I can't import same python module from different path. Any ideas? 0_o

P.S. SELINUX=disabled

+2  A: 

What's dns.__file__ in the first case? I suspect it's not coming from the directory you cded into the second time (the current directory when you start Python goes at the front of sys.path) but rather from a package containing that crucial resolver module which the second one appears to be lacking.

Alex Martelli
>>> import dns>>> dns.__file__'/usr/local/lib/python2.6/site-packages/dns/__init__.pyc'>>>Absolute path
Choor
Bingo: the `dns` subdirectory of `site-packages` clearly has all you need, while the `dns` subdirectory of `dev/dns` doesn't (it's missing the `resolver` module, or the `.pth` file to direct to it, or something of that ilk).
Alex Martelli
Actually the presence in the working directory of a `dns.py` which gets imported instead of the package is plenty explanation enough. If you _don't_ want imports to be resolved from the current directory (as Python normally behaves) you can modify `sys.path` before importing, of course.
Alex Martelli
@Alex Now it's work ;) Thank you for help
Choor
@Choor, you're welcome: also consider accepting the answer (thanks are nice but accepts are key: that's SO etiquette!-). Just clicking on the checkmark-shaped icon below the numbers on the upper left of the answer will do that.
Alex Martelli
@Alex Done... ;)
Choor