【发布时间】:2016-01-20 03:42:13
【问题描述】:
我是 python 新手,我正在编写一个简单的 TCP 服务器Server.py,我正在尝试使用这行代码导入反应器
from twisted.internet import reactor
问题是当我运行代码时出现此错误
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/Nora/PycharmProjects/Server/Server.py
Traceback (most recent call last):
File "/Users/Nora/PycharmProjects/Server/Server.py", line 2, in <module>
from twisted.internet import reactor
ImportError: No module named 'twisted'
注意我使用的是OS X Yosemite,并且我已经安装了一个新的python 3.5版本,我怎样才能回到已经扭曲的系统内置版本?
【问题讨论】:
-
从默认的python安装目录运行程序?
-
你安装twisted?这不是基本的。 “pip install twisted” 如果你使用python3.5,你可以使用asyncio来代替twisted。总比扭曲好。否则你在 python2.x 中使用twisted。
-
我不知道我会简单地说 asyncio 比扭曲更好,它们在不同的领域运行。 Glyph 在 glyph.twistedmatrix.com/2014/05/the-report-of-our-death.html 和 Autobahn (websocket lib) 作者在 autobahn.ws/python/asynchronous-programming.html 中很好地涵盖了这一点
标签: python tcp twisted reactor twisted.internet