python模块导入错误

发布于 2024-10-20 12:00:45 字数 2257 浏览 7 评论 0原文

我正在使用 macports 安装各种模块。一般来说,这工作得很好,但下面是我遇到的一个不容易解决的错误:

$ 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

这可能是路径问题吗?

>>> 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 [评论被删减] # DNS 类的 init.py。

__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

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

§对你不离不弃 2024-10-27 12:00:45

因为您需要执行以下操作:

from dns import resolver

这不起作用:

import datetime.datetime

但这可以:

from datetime import datetime

如果您要导入属于另一个包的包,则需要使用“from”语法

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

一梦等七年七年为一梦 2024-10-27 12:00:45

我卸载了 py26-dnspython 并重新安装。问题解决了。 Fink 对 freenode 提出了建议。谢谢。

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

無心 2024-10-27 12:00:45

我使用的是 Python 3.7 并且安装了 pubdns。这解决了我的问题。
我在使用 py3dns、pyDNS(无法安装)、dnspython 等方面遇到了极大的困难

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文