python - 由于错误卸载Python而在Mac上破坏了Python,如何让模块再次工作?

标签 python macos twisted homebrew zope

我正在尝试将 Python 与 Twisted 框架结合使用,但一直在努力让它运行。

我有一些非常简单的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。

最佳答案

您应该在 virtualenv 中完成所有 Python 工作。 。如果您要为 Twisted 开发创建一个新的 virtualenv,并且始终在使用它之前激活它,那么您将对安装的内容有更严格的控制,并且诊断问题也会容易得多。因此,请创建一个新的 virtualenv 并在其中 pip install twins ,然后这个问题就会消失。

关于python - 由于错误卸载Python而在Mac上破坏了Python,如何让模块再次工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32831290/

相关文章:

python - dataReceived 接收了多少字节?

python - Twisted Matrix,将自定义类挂接到事件循环

python - 将 DataFrame 列数据转换为数组

python - 我怎样才能对字典中的数字列表进行平方?

macos - 捕获 NSTextField 内的选项/命令键

php - 无法在 mac os Sierra 上启动 xampp?

基于 Python 扭曲事件的 jabber/xmpp/email/irc/chat 客户端,用于监听和响应消息

python - Pandas 中的日期时间格式不一致

python - 无法从网页的某些脚本标记中获取电子邮件链接

cocoa - 创建 "stop progress"按钮(如 Safari 的下载窗口)的最佳方法是什么?