python - 与 Python 安装的模块不匹配

标签 python homebrew

我是一个 Python 新手,正在努力完成看似简单的任务。

我已在 Mac 上使用 Homebrew 安装了 Python。当我运行 which python 时,它返回 /usr/local/bin/python ,当我运行 ls -al/usr/local/bin/python 时> 我可以看到python的符号链接(symbolic link)如下/usr/local/bin/python -> ../Cellar/python/2.7.1/bin/python,表明安装了Homebrew版本的Python .

现在,当我安装 boto 模块时,我这样做了: easy_install boto 它告诉我该模块已安装到 /Library/Python/2.7/site-packages/boto-2.2.2-py2.7.egg

奇怪的是,当我执行以下操作时,我被告知 boto 模块不存在。

$ python
Python 2.7.1 (r271:86832, Aug 31 2011, 23:21:36)
>>> import boto
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named boto

为什么该模块不可用?这几乎就像 Homebrew 将模块安装到标准库文件夹中,但在搜索已安装的模块时不会链接回该目录。

谁能解释一下这是怎么回事?

谢谢

最佳答案

easy_install是一个调用特定版本的python的脚本。在你的情况下它一定指向了错误的python。

% which easy_install
/usr/bin/easy_install

请注意,在我的示例中,easy_install 正在调用 /usr/bin/python:

% head -n1 /usr/bin/easy_install
#! /usr/bin/python

将第一行更改为指向 /usr/local/bin/python

或者,您安装的 Homebrew 可能会附带其自己的 easy_install。在这种情况下,只需找到 Homebrew 的 easy_install 并调用它即可。

关于python - 与 Python 安装的模块不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9532703/

相关文章:

python - 单击按钮上的 wxPython/ReportLab : How to create and open a . pdf 文件

python - re.findall 不返回完整匹配?

python - 如何在 python 中获得按创建日期排序的目录列表?

python - 将 numpy 数组映射到 pandas DataFrame 会导致 ValueError

java - 在 MAC OS X 10.11 上使用 Homebrew 软件安装 ant 无法正常工作

ruby-on-rails - rbenv、 Homebrew 软件和 postgres9.3 : pg upgrade form 9. 2 损坏了 pg

python - python 3 中缺少 argparse

python - 当命令 `Brew install python@2` 然后错误 - `Theme error`。如何解决?

python - 无法在 OS X 上使用 boost-python 编译 python 绑定(bind)

ruby - 在 macOS 上升级全局 Ruby 版本