【问题标题】:Installing pip on macOS Sierra在 macOS Sierra 上安装 pip
【发布时间】:2017-05-05 03:42:17
【问题描述】:

我一直在尝试通过 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

【问题讨论】:

  • sudo easy_install 没有将 pip 放入 brew 目录
  • pip2 存在吗?
  • @cricket_007 在/usr/local/Cellar/python/2.7.13/bin 中没有pippip2

标签: python macos pip macos-sierra


【解决方案1】:

您只需要安装pip,它不会自动安装在 macOS Sierra 中。

运行sudo easy_install pip

【讨论】:

  • 工作就像一个魅力:-)
【解决方案2】:

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

所以如下使用curl安装pip,

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

【讨论】:

  • 我可以确认这个命令在 MacOS Sierra v10.12.5 上就像一个魅力!其他执行此操作的单个命令均以不同的方式失败。谢谢!!
  • 在 Catalina 也为我工作过。
【解决方案3】:

好的,伙计们,很多这些答案都很有帮助,但没有一个能让我到达终点。我正在运行 High Sierra 10.13.4。上面记录的问题是 Brew 将 pip 安装在 /usr/local/bin 目录中,但 Python 在 /usr/bin 中(尽管正如 Carl 所说,Python3 正确地转到 /usr/local/bin)。

我的直接用例与安装 Postgres BigSQL 软件包有关。

我采取的步骤如下:

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

【讨论】:

    【解决方案4】:

    您的 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
    

    【讨论】:

    • 好的,当我运行brew postinstall python 时出现错误。请参阅原始问题以获取更新。
    • 不确定为什么需要运行它,但它对我来说很好用。尝试删除~/Library/Caches/Homebrew的缓存文件
    【解决方案5】:

    我遇到了这个问题,我发现这是解决方案。 BTW pip 不是通过 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 安装并使用 python 的 brew 版本。

    现在在高山脉之前 python 曾经位于 /usr/local/bin 但由于某种原因,如果你将 /usr/local/bin 放在你的路径中,它会自动指向 /usr/bin,所以这是我能够得到的唯一解决方案跟上。

    Python3 没有这个问题,如果你brew install python3 并输入which python3 你会看到它位于/usr/local/bin/python3

    【讨论】:

      【解决方案6】:

      不管怎样,升级到 high sierra 后,我发现我的机器几乎无法用于开发,甚至多次崩溃。

      关于 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
      

      希望对您有所帮助。

      【讨论】:

        【解决方案7】:

        错误信息有你的答案...

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

        【讨论】:

          猜你喜欢
          • 2018-10-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-12-05
          • 2017-05-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多