Python twisted ImportError: cannot import name unicode

Python twisted ImportError: cannot import name unicode

我扭曲的依赖关系出了点问题,它起作用了,现在我在导入协议和反应器时遇到这个错误:

Python 2.7.8 (default, Nov 25 2014, 09:23:41)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from twisted.internet import reactor, protocol
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nick/env/env/lib/python2.7/site-packages/twisted/__init__.py", line 56, in <module>
    from twisted.python import compat
  File "/home/nick/env/env/lib/python2.7/site-packages/twisted/python/compat.py", line 23, in <module>
    import sys, string, socket, struct
  File "socket.py", line 1, in <module>
    from twisted.internet.protocol import Protocol, Factory
  File "/home/nick/env/env/lib/python2.7/site-packages/twisted/internet/protocol.py", line 17, in <module>
    from twisted.python import log, failure, components
  File "/home/nick/env/env/lib/python2.7/site-packages/twisted/python/log.py", line 19, in <module>
    from twisted.python.compat import unicode, _PY3
ImportError: cannot import name unicode

这就是 Python 搜索和包含库的方式。在我的目录中有一个名为 socket.py 的文件 在我的脚本中,我包含了 "from twisted.internet import reactor, protocol" Twisted lib 加载套接字库 - 所以我的 socket.py 开销标准库。 因此,请谨慎使用命名脚本...

此外,如果您加载 python 控制台,当前目录包括作为库搜索路径。