2
很奇怪我:Python模塊導入錯誤
# 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 [[email protected] 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 #
總結:我不能從不同的路徑導入相同的Python模塊。 任何想法? 0_o
P.S. SELINUX =禁用
>>>進口DNS >>> DNS .__ FILE__ '/usr/local/lib/python2.6/site-packages/dns/__init__.pyc' >>> 絕對路徑 – ololo 2010-05-23 19:16:50
賓果:在「site-packages」的'dns'子目錄顯然是你所需要的,而'dev/dns'的'dns'子目錄不是(它缺少'resolver'模塊或者'.pth'文件來指向它或類似的東西)。 – 2010-05-23 20:26:06
實際上,在工作目錄中存在一個'dns.py'而不是包被導入,這足以說明問題。如果您不想從當前目錄中解析導入(正如Python通常所做的那樣),當然可以在導入之前修改'sys.path'。 – 2010-05-23 20:27:40