Python module import error

I use macports to install various modules. This usually works well, but below is the error I get that I am not easily resolving:

$ python Python 2.6.6 (r266:84292, Feb 12 2011, 16:57:53) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import dns >>> import opcode >>> from dns import resolver Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dns/resolver.py", line 26, in <module> import dns.message File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dns/message.py", line 28, in <module> import dns.opcode ImportError: No module named opcode 

Could this be a path problem?

 >>> import sys >>> sys.path ['', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info'] 

$ cat / opt / local / Library / Frameworks / Python.framework / Versions / 2.6 / lib / python2.6 / site-packages / dns / init .py [cut-off comments] # init .py for the DNS class.

 __version__ = '2.3.3' import Type,Opcode,Status,Class from Base import DnsRequest, DNSError from Lib import DnsResult from Base import * from Lib import * Error=DNSError from lazy import * Request = DnsRequest Result = DnsResult 

Thanks in advance.

+4
source share
3 answers

Because you need to do:

 from dns import resolver 

This does not work:

 import datetime.datetime 

But it does:

 from datetime import datetime 

If you are importing a package that is part of another package, you need to use the "from" syntax

+6
source

I uninstalled py26-dnspython and reinstalled. The problem is solved. Fink on freenode made a proposal. Thanks.

+2
source

I am using Python 3.7 and I have installed pubdns. This solved my problem. I ran into huge difficulties when using py3dns, pyDNS (not install), dnspython and many others

0
source

Source: https://habr.com/ru/post/1342445/


All Articles