我试图在Twisted框架中使用Python,并一直在努力让它运行。
我有一些简单的python代码:
from twisted.internet import reactor
reactor.run()
我跑步时买python server.py
我回来了:
File "server.py", line 1, in <module> from twisted.internet import reactor File "/Library/Python/2.7/site-packages/twisted/__init__.py", line 53, in <module> _checkRequirements() File "/Library/Python/2.7/site-packages/twisted/__init__.py", line 37, in _checkRequirements raise ImportError(required + ": no module named zope.interface.") ImportError: Twisted requires zope.interface 3.6.0 or later: no module named zope.interface.
我的第一个假设是运行pip install zope.interface
不幸的是,我从中得到的只有:
Requirement already satisfied (use --upgrade to upgrade): zope.interface in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python Requirement already satisfied (use --upgrade to upgrade): setuptools in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from zope.interface)
我也试过easy_install zope.interface
但是产生了类似的结果:
Searching for zope.interface Best match: zope.interface 4.1.1 zope.interface 4.1.1 is already the active version in easy-install.pth Using /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python Processing dependencies for zope.interface Finished processing dependencies for zope.interface
由于显然我的机器上安装了zope,我认为问题可能出在我安装的python上。我在今年早些时候用brew安装了Python3,我想我可能搞砸了python配置。有什么想法吗?
更新 Mac上的默认python应该适用于我上面尝试的所有内容,我在另一台Mac计算机上验证了这一点。我遇到的问题是我已经破坏了我的mac附带的默认python图像。按照下面的帖子,我能够为我的python再次创建工作virtualenv。
答案 0 :(得分:2)
您应该在virtualenv中完成所有Python工作。如果你要为你的Twisted开发制作一个新的virtualenv,并且在开始之前总是激活它,你就可以更加严格地控制安装的内容,并且诊断问题会容易得多。所以请在其中制作一个新的virtualenv并pip install twisted
,然后这个问题就会消失。