我正在使用MacOSX10.9.1,我记得不久前安装了Python (考虑到Mac附带了,我不记得为什么)。由于某种原因,Twisted没有安装,所以我安装了Zope和Twisted。
我正在学习本教程:http://www.raywenderlich.com/3932/networking-tutorial-for-ios-how-to-create-a-socket-based-iphone-app-and-server
问题是,当我运行这段代码时:
from twisted.internet.protocol import Factory,Protocol
from twisted.internet import reactor
class IphoneChat(Protocol):
def connectionMade(self):
print "a client connected"
factory = Factory()
factory.protocol = IphoneChat
reactor.listenTCP(80, factory)
print "Iphone Chat server started"
reactor().run我知道这个错误:
Traceback (most recent call last):
File "/Users/Mattieman/Desktop/server.py", line 4, in <module>
from twisted.internet import reactor
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted/internet/reactor.py", line 38, in <module>
from twisted.internet import default
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted/internet/default.py", line 56, in <module>
install = _getInstallFunction(platform)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted/internet/default.py", line 52, in _getInstallFunction
from twisted.internet.selectreactor import install
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted/internet/selectreactor.py", line 18, in <module>
from twisted.internet import posixbase
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted/internet/posixbase.py", line 53, in <module>
from twisted.internet import process, _signals
ImportError: cannot import name process所以我在/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted/internet看了看
...and,看来process.py不见了。
我做什么好?
似乎也有其他文件丢失,如_baseprocess.py
我用了setup3.py,如果有帮助的话.
发布于 2014-02-05 22:42:37
您正在使用Python2.6。你不应该使用setup3.py。您也不应该使用distutils setup.py-type脚本将Python安装到OS路径中(比如/Library/Frameworks/Python.framework/Versions/2.6/)。
现在您的系统上可能有一个随机损坏的Twisted安装(OS本身附带了Twisted的副本)。或者您可能只是在/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted中有一些需要清理的垃圾。很难说是哪一个(这就是为什么您不应该使用setup.py来安装东西--这会留下很大的麻烦)。
在你清理掉这些烂摊子后(除了“重新安装你的OS X”之外,我不能给你很多建议),你有几个选择:
setup.py install --user (--user告诉它把它的烂摊子留在~/.local中,至少不会破坏您的OS安装)。其中,您可能想要使用虚拟环境。
还请注意,除非您试图安装Twisted for Python3,否则您不应该运行setup3.py。如果您试图安装Twisted,那么我将警告您,只有部分Twisted是移植的--而且这是一个非常小的部分。例如,它不是进程支持(因此您得到了导入错误)。
https://stackoverflow.com/questions/21589769
复制相似问题