4

I am using macports to install various modules. Generally this works well, but below is an error I am getting 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 issue?

>>> 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 [snipped comments] # init.py for 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.

asked Mar 5, 2011 at 19:58
1
  • from dns import resolver doesn't work? Can you post the content of __init__.py inside /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dns/? Commented Mar 5, 2011 at 20:23

3 Answers 3

8

Because you need to do:

from dns import resolver

This doesn't work:

import datetime.datetime

But this does:

from datetime import datetime

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

answered Mar 5, 2011 at 21:20
Sign up to request clarification or add additional context in comments.

4 Comments

have you tried import dns, resolver = dns.resolver? You've already got the dns package imported.
I have tried that now, and I still get an error: AttributeError: 'module' object has no attribute 'resolver'
I am able to import other modules from dns with no problem: tokenizer, reversename, ipv6, etc. Only resolver produces an error.
Ok. Found some other packages from dns that produce an error: update, win32dns, e164, (just noticed that the package Opcode is not lower case - wondering if that has something to do with it), message, haven't tested them all.
2

I uninstalled py26-dnspython and reinstalled. Problem solved. Fink on freenode made the suggestion. Thanks.

answered Mar 6, 2011 at 2:37

Comments

0

I am using Python 3.7 and I installed pubdns. This resolved my problem. I faced extreme difficulty in using py3dns, pyDNS (won't install), dnspython and many more

answered Jul 25, 2019 at 17:15

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.