在macOS Sierra上安装pip

时间:2016-12-20 01:28:03

标签: python macos pip macos-sierra

我一直在尝试通过brew在macOS sierra上安装pip,但每次完成都没有在/usr/local/Cellar/python/2.7.13/bin中安装二进制文件。

我试过了:

MacBook-Pro ➜ brew reinstall python

然后:

MacBook-Pro ➜  ~ which pip
pip not found

我找到了python的路径,它是/usr/local/Cellar/python/2.7.13/bin但没有二进制用于pip。

我也尝试了easy_install方法:

MacBook-Pro ➜ sudo easy_install pip
Traceback (most recent call last):
  File "/usr/bin/easy_install-2.7", line 11, in <module>
    load_entry_point('setuptools==18.5', 'console_scripts', 'easy_install')()
  File "/Library/Python/2.7/site-packages/pkg_resources.py", line 352, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/Library/Python/2.7/site-packages/pkg_resources.py", line 2307, in load_entry_point
    return ep.load()
  File "/Library/Python/2.7/site-packages/pkg_resources.py", line 2021, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/__init__.py", line 12, in <module>
    from setuptools.extension import Extension
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/extension.py", line 8, in <module>
    from .dist import _get_unpatched
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/dist.py", line 21, in <module>
    packaging = pkg_resources.packaging
AttributeError: 'module' object has no attribute 'packaging'

更新

当我运行brew postinstall python时,我收到以下错误:

MacBook-Pro ➜  ~ brew postinstall python
==> Using the sandbox
==> /usr/local/Cellar/python/2.7.13/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --rec
==> /usr/local/Cellar/python/2.7.13/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --rec
Last 15 lines from /Users/justin/Library/Logs/Homebrew/python/post_install.02.python:

Traceback (most recent call last):
  File "setup.py", line 92, in <module>
    cmdclass={'test': PyTest},
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 111, in setup
    _setup_distribution = dist = klass(attrs)
  File "/Users/justin/.venvburrito/lib/python/distribute-0.6.35-py2.7.egg/setuptools/dist.py", line 225, in __init__
    _Distribution.__init__(self,attrs)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 287, in __init__
    self.finalize_options()
  File "/Users/justin/.venvburrito/lib/python/distribute-0.6.35-py2.7.egg/setuptools/dist.py", line 258, in finalize_options
    ep.load()(self, ep.name, value)
  File "/Users/justin/.venvburrito/lib/python/distribute-0.6.35-py2.7.egg/pkg_resources.py", line 2020, in load
    raise ImportError("%r has no %r attribute" % (entry,attr))
ImportError: <module 'setuptools.dist' from '/Users/justin/.venvburrito/lib/python/distribute-0.6.35-py2.7.egg/setuptools/dist.pyc'> has no 'check_specifier' attribute

7 个答案:

答案 0 :(得分:40)

您只需要安装未在macOS Sierra中自动安装的pip

运行sudo easy_install pip

答案 1 :(得分:11)

对于Mac OS Sierra,由于TLS版本存在问题,因此无法通过easy_install安装pip,已安装的Open-SSL版本不支持TLS 1.2

因此,请按如下所示使用curl安装pip,

curl https://bootstrap.pypa.io/get-pip.py | sudo python

答案 2 :(得分:4)

好的帮派,很多这些答案都很有帮助,但没有一个能让我走到终点。我正在运行High Sierra 10.13.4。上面记录的问题是Brew在data = [ ["51.9435", "-4.26697", "450", "125"], ["51.9437", "-4.26717", "450", "125"], ["51.9438", "-4.26733", "450", "125"], ["51.944", "-4.26748", "450", "125"], ] data.forEach( arr => { // loop over all arrays to get the individual ones. arr.splice(2 , 1) // then call splice. }) console.log(data) 目录中安装了pip,但Python在/usr/local/bin中(虽然正如Carl所说,Python3正确地转到了/usr/bin)。

我的直接用例与获取Postgres BigSQL软件包有关。

我采取的步骤如下:

  1. 清除brew缓存/usr/local/bin
  2. 清除网站包$ rm -rf ~/Library/Caches/Homebrew
  3. 重新安装Python $ sudo rm -rf /usr/local/lib/python2.7/site-packages这会将$ brew reinstall python下拉并放入python-3.5.6.high_sierra
  4. /usr/local/bin/python3仍显示which python
  5. 解决方案将运行/usr/bin/python,结果为brew install python@2
  6. 现在python@2-2.7.14_3.high_sierra显示了正确的路径which python,这也是所有pip内容的安装位置,所以现在pip可以正常工作。
  7. 当然,如果您还没有安装最新版本的pip,那么您应该使用/usr/local/bin/python

答案 3 :(得分:3)

brew安装必定有问题。

最新的macOS版本。

 ~/ brew reinstall python
==> Reinstalling python
==> Downloading https://homebrew.bintray.com/bottles/python-2.7.13.sierra.bottle.tar.gz
Already downloaded: ~/Library/Caches/Homebrew/python-2.7.13.sierra.bottle.tar.gz
==> Pouring python-2.7.13.sierra.bottle.tar.gz
==> Using the sandbox
==> /usr/local/Cellar/python/2.7.13/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python/2.7
==> /usr/local/Cellar/python/2.7.13/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python/2.7
==> /usr/local/Cellar/python/2.7.13/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python/2.7
==> Caveats
Pip and setuptools have been installed. To update them
  pip install --upgrade pip setuptools

You can install Python packages with
  pip install <package>

They will install into the site-package directory
  /usr/local/lib/python2.7/site-packages

See: https://github.com/Homebrew/brew/blob/master/docs/Homebrew-and-Python.md

.app bundles were installed.
Run `brew linkapps python` to symlink these to /Applications.
==> Summary
  /usr/local/Cellar/python/2.7.13: 3,526 files, 48M

它肯定存在。

 ~/ ls -l $(which pip)
lrwxr-xr-x  1 cricket  admin  31 Dec 19 19:43 /usr/local/bin/pip -> ../Cellar/python/2.7.13/bin/pip

答案 4 :(得分:3)

我有这个问题,我发现这是解决方案。 BTW点不是通过brew安装的。它带有python和python virtualenvs。

如果您在没有which python的情况下输入brew install python,您将获得/usr/bin/python中的位置信息。这是我们不想用它开发的系统python。

所以我采取了以下步骤。 1)brew install python 2)export PATH="/usr/local/opt/python/libexec/bin:$PATH"将其放在~/.bash_profile中 3)终端中的source ~/.bash_profile 4)键入which python,并且应该将位置更改为/usr/local/opt/python/libexec/bin/python

这将允许您正常进行pip安装并使用brew版本的python。

现在高sierra python曾经位于/usr/local/bin之前,但出于某种原因,如果你在路径中放置/usr/local/bin它会自动指回/usr/bin,所以这是唯一的解决方案我能够想出来。

Python3没有此问题,如果您brew install python3并输入which python3,您会发现它位于/usr/local/bin/python3

答案 5 :(得分:1)

对于它的价值,升级到高山脉之后,我发现我的机器几乎无法用于开发,甚至崩溃很多次。

关于python,我在site-packages文件夹中有一个权限问题,因此重新安装没有用完:

$ brew reinstall python

==> Reinstalling python
==> Downloading https://homebrew.bintray.com/bottles/python-2.7.14.high_sierra.bottle.tar.gz
Already downloaded: /Users/m/Library/Caches/Homebrew/python-2.7.14.high_sierra.bottle.tar.gz
==> Pouring python-2.7.14.high_sierra.bottle.tar.gz
==> /usr/local/Cellar/python/2.7.14/bin/python2 -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python/2.7.14/bin --install-
Last 15 lines from /Users/m/Library/Logs/Homebrew/python/post_install.01.python2:
.
.
.
copying build/lib/setuptools/script (dev).tmpl -> /usr/local/lib/python2.7/site-packages/setuptools
copying build/lib/pkg_resources/_vendor/packaging/version.py -> /usr/local/lib/python2.7/site-packages/pkg_resources/_vendor/packaging
error: could not delete '/usr/local/lib/python2.7/site-packages/pkg_resources/_vendor/packaging/version.py': Permission denied
Warning: The post-install step did not complete successfully
...

为了解决这个问题,我完全删除了网站包:

$ sudo rm -rf /usr/local/lib/python2.7/site-packages

有了这个,重新安装python2,并再次使用pip2,就像一个魅力:

$ brew reinstall python

$ which pip2
/usr/local/bin/pip2
$ which python2
/usr/local/bin/python2

$ which pip
pip not found
$ which python
/usr/bin/python

希望有所帮助。

答案 6 :(得分:0)

错误消息为您提供了答案......

删除/Users/justin/.venvburrito/lib/python/distribute-0.6.35-py2.7.egg/并运行brew reinstall pythonsetuptools版本错误。