【问题标题】:pip on OSX Yosemite 10.10 gives bad commandOSX Yosemite 10.10 上的 pip 给出了错误的命令
【发布时间】:2015-04-23 13:24:07
【问题描述】:

我在 macbook air 上运行 OSX Yosemite。我安装了 python3 以及苹果开发者包。我正在尝试安装我已经安装的模块,包括 matplotlib。基本上,当我尝试安装 SciPy、Ginga、AstroPy、iPython 等科学 python 包时,我在尝试 pip 安装后会在终端中得到这个:

-bash: pip: command not found

因此,如果提供了 tarball,我会尝试下载该 tarball,并按照网站和 README 文件的指导按照说明进行安装,但仍然出现错误。例如,在这个 astropy tarball 中,它声明从目录运行 python setup.py install ,这就是发生的情况:

jesses-Air:astropy-1.0 jessehanowell$ python setup.py install
running install
Checking .pth file support in /Library/Python/2.7/site-packages/
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

[Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-

install-632.pth'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

/Library/Python/2.7/site-packages/

Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

https://pythonhosted.org/setuptools/easy_install.html

Please make the appropriate changes for your system and try again.

“python3 setup.py install”命令也是如此。请记住,我已经安装了 python3 并且 Yosemite 仍然在 python v2.4.7 上运行,并且我正在从文件所在的下载目录运行终端。也许我必须将文件解压缩文件更改为新位置?但基本上我很失望,因为我真的很想学习使用这些包。我知道我的朋友是否能够安装 matplotlib,我应该能够安装这些。

那么有没有办法将 pip 恢复到我的计算机并以这种方式安装?或者有人可以指出我做错了明显的事情吗?谢谢各位帮忙!

【问题讨论】:

  • Homebrew installs pip 当你用brew install python安装python时。
  • 我在 mac 上运行了 python3。为什么我需要重新安装 python?
  • 如果您使用自制软件安装了 python 或 python3,您将安装 pip。看起来在 python(3) 的时候没有安装 pip。
  • 运行python setup.py install --user。此外,找不到 pip 命令意味着您必须install pip first,这将是您最好的行动方案。更好的是,只需使用自制软件,因为自己设置包的配置可能很麻烦。
  • 我使用了 pip3 并且成功了!

标签: macos python-3.x scipy pip astropy


【解决方案1】:

对于阅读其他一些回复的任何人,我应该强调您应该使用sudo 来绕过权限错误 - 相反,运行安装命令:

python setup.py install --user

这会将软件包安装到您主目录中的Library

一般来说,我实际上建议使用Anaconda Python Distribution 在 Mac 上安装 Scientific Python 发行版(默认包括 Numpy、SciPy、Astropy 等)。

【讨论】:

    【解决方案2】:

    权限被拒绝问题通常意味着您需要在命令前加上 sudo。

    这是我做的一篇文章,其中包括使用自制软件安装 python:

    https://rlkamradt.wordpress.com/2015/02/14/setting-up-a-development-environment-on-a-mac-languages/

    【讨论】: