【问题标题】:Cannot get Twisted to work on a Mac无法 Twisted 在 Mac 上工作
【发布时间】:2018-12-10 07:12:24
【问题描述】:

我正在尝试运行与https://pawelmhm.github.io/python/websockets/2016/01/02/playing-with-websockets.html 上的文章相关的源代码,但无法让 Twisted 工作。我正在使用 macOS High Sierra 10.13.5 和 Python 3.6.4(在虚拟环境中)。

创建我使用的虚拟环境: python3 -m venv venv . venv/bin/activate

其中python3是我系统安装的python 3.6.4: $ which python3 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3

我尝试使用 pip 安装twis​​ted:

$ pip install twisted
Collecting twisted
  Downloading https://files.pythonhosted.org/packages/12/2a/e9e4fb2e6b2f7a75577e0614926819a472934b0b85f205ba5d5d2add54d0/Twisted-18.4.0.tar.bz2 (3.0MB)
    100% |████████████████████████████████| 3.0MB 1.9MB/s 
Collecting zope.interface>=4.4.2 (from twisted)
  Downloading https://files.pythonhosted.org/packages/ac/8a/657532df378c2cd2a1fe6b12be3b4097521570769d4852ec02c24bd3594e/zope.interface-4.5.0.tar.gz (151kB)
    100% |████████████████████████████████| 153kB 281kB/s 
Collecting constantly>=15.1 (from twisted)
  Downloading https://files.pythonhosted.org/packages/b9/65/48c1909d0c0aeae6c10213340ce682db01b48ea900a7d9fce7a7910ff318/constantly-15.1.0-py2.py3-none-any.whl
Collecting incremental>=16.10.1 (from twisted)
  Downloading https://files.pythonhosted.org/packages/f5/1d/c98a587dc06e107115cf4a58b49de20b19222c83d75335a192052af4c4b7/incremental-17.5.0-py2.py3-none-any.whl
Collecting Automat>=0.3.0 (from twisted)
  Downloading https://files.pythonhosted.org/packages/a3/86/14c16bb98a5a3542ed8fed5d74fb064a902de3bdd98d6584b34553353c45/Automat-0.7.0-py2.py3-none-any.whl
Collecting hyperlink>=17.1.1 (from twisted)
  Downloading https://files.pythonhosted.org/packages/a7/b6/84d0c863ff81e8e7de87cff3bd8fd8f1054c227ce09af1b679a8b17a9274/hyperlink-18.0.0-py2.py3-none-any.whl
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from zope.interface>=4.4.2->twisted) (28.8.0)
Collecting attrs>=16.1.0 (from Automat>=0.3.0->twisted)
  Downloading https://files.pythonhosted.org/packages/41/59/cedf87e91ed541be7957c501a92102f9cc6363c623a7666d69d51c78ac5b/attrs-18.1.0-py2.py3-none-any.whl
Requirement already satisfied: six in /Users/sumit/Library/Python/3.6/lib/python/site-packages (from Automat>=0.3.0->twisted) (1.11.0)
Collecting idna>=2.5 (from hyperlink>=17.1.1->twisted)
  Downloading https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 2.8MB/s 
Installing collected packages: zope.interface, constantly, incremental, attrs, Automat, idna, hyperlink, twisted
  Running setup.py install for zope.interface ... done
  Running setup.py install for twisted ... done
Successfully installed Automat-0.7.0 attrs-18.1.0 constantly-15.1.0 hyperlink-18.0.0 idna-2.7 incremental-17.5.0 twisted-18.4.0 zope.interface-4.5.0

但我不断收到错误消息:

$ python server.py
Traceback (most recent call last):
  File "server.py", line 4, in <module>
    from twisted.web.static import File
ModuleNotFoundError: No module named 'twisted'

在网络上搜索没有得到有用的解决方案,并且尝试使用 easy_installbrew 也不起作用。任何建议表示赞赏。

【问题讨论】:

  • 你能做一个pip freeze | grep -i twisted 并分享结果吗?
  • 您的pippython 可能彼此不对应。请改用python -m pip install twisted
  • 投票关闭,因为无法回答这个问题(因为缺少的信息太多)而且它通常没有用(“如何在我的 macOS 计算机上安装 Python 模块”没有概括)。一个不同的 SO 站点可能会有所帮助,也许是超级用户。
  • @9769953,谢谢,这解决了问题。您想发表您的评论作为答案吗?我已经添加了我的答案,但如果你发布你的答案,我会删除它。感谢您帮助解决这个问题!

标签: python python-3.x macos twisted macos-high-sierra


【解决方案1】:

谢谢@9769953,解决了问题!

如果其他人搜索此问题(以及供我将来参考!),请使用: python -m pip install twisted

我确实有一个虚拟环境,但显然 python 和 pip 的组合搞砸了。使用python -m pip 解决了依赖问题。

【讨论】:

  • 做一个which pipwhich python 看看你在用什么。您可能没有正确初始化您的 virtualenv,但如果没有更多细节,这很难弄清楚。
  • 是的,我尝试了这些命令,但问题确实是使用了不正确的 pip。我使用python3 -m venv venv 创建了虚拟环境,其中python3 指向我的系统Python 3.6.4 安装。我希望 pip 也可以安装,显然不是。感谢你,我今天学会了python -m pip 技巧。
  • 嗯;很好奇为什么在您的虚拟环境中找不到pip。你source venv/bin/activate了吗? venv/bin/目录下是否有pip脚本?
  • 我做了 source venv/bin/activate。但是 venv/bin 中没有 pip。可能是什么原因?它只有四个文件:activate activate.csh activate.fish python python3。所有其他虚拟环境都有 pip。
  • 有趣。但是安装了pip包,所以pip是可用的。
猜你喜欢
  • 1970-01-01
  • 2017-01-23
  • 2018-02-12
  • 2011-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-27
  • 1970-01-01
相关资源
最近更新 更多