Python 无法在Mac上工作

Python 无法在Mac上工作,python,python-3.x,macos,twisted,macos-high-sierra,Python,Python 3.x,Macos,Twisted,Macos High Sierra,我正在尝试运行与上的文章相关联的源代码,但无法正常工作。我正在使用macOS High Sierra 10.13.5和Python 3.6.4(在虚拟环境中) 要创建我使用的虚拟环境,请执行以下操作: 蟒蛇3-m静脉 . venv/bin/激活 其中python3是我的系统安装的python3.6.4: $3哪条蟒蛇 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 我尝试使用pip安装twisted: $ pip

我正在尝试运行与上的文章相关联的源代码,但无法正常工作。我正在使用macOS High Sierra 10.13.5和Python 3.6.4(在虚拟环境中)

要创建我使用的虚拟环境,请执行以下操作:

蟒蛇3-m静脉
. venv/bin/激活

其中python3是我的系统安装的python3.6.4:

$3哪条蟒蛇
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3

我尝试使用pip安装twisted:

$ 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'
$python server.py
回溯(最近一次呼叫最后一次):
文件“server.py”,第4行,在
从twisted.web.static导入文件
ModuleNotFoundError:没有名为“twisted”的模块

在web上搜索没有得到有用的解决方案,尝试使用
easy\u install
brew
也不起作用。感谢您的建议。

谢谢@9769953,这解决了问题

如果其他人搜索此问题(以及我将来的参考!),请使用:

python-mpip安装程序


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

您可以执行
pip冻结| grep-i twisted
并共享结果吗?您的
pip
python
可能彼此不对应。尝试使用
python-m pip install twisted
。投票关闭,因为无法回答这个问题(因为缺少太多信息),而且通常没有什么用处(“如何在macOS计算机上安装python模块”没有概括)。另一个SO站点可能会有所帮助,可能是超级用户。@9769953,谢谢,这解决了问题。你想把你的评论作为答案吗?我已经添加了我的答案,但如果你发布你的答案,我会删除它。感谢您帮助解决此问题!执行
哪个pip
哪个python
查看您正在使用什么。您可能没有正确初始化virtualenv,但如果没有更多详细信息,这很难理解。是的,我尝试了这些命令,问题确实是使用了不正确的pip。我使用
python3-mvenv
创建了虚拟环境,其中python3指向我的系统python3.6.4安装。我希望pip也能安装它,显然不是。多亏了你,我今天学会了
python-mpip
技巧;好奇为什么在虚拟环境中找不到
pip
。您是否
源venv/bin/activate
?在
venv/bin/
目录中是否有
pip
脚本?我确实激活了source-venv/bin/activate。但venv/bin中没有pip。原因可能是什么?它只有四个文件:
activate-activate.csh-activate.fish-python3
。所有其他虚拟环境都有pip.interest。但是安装了pip包,所以可以使用pip。