2016-12-20 42 views
8

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

我已经试过:

MacBook-Pro ➜ brew reinstall python 

则:

MacBook-Pro ➜ ~ which pip 
pip not found 

我发现的路径,蟒蛇,这是/usr/local/Cellar/python/2.7.13/bin但没有二进制的点子出现。

我也试过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' 

UPDATE:

当我运行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 
+0

'sudo easy_install'不会将pip放入brew目录 –

+0

'pip2'是否存在? –

+0

@ cricket_007 no'pip'或'pip2'在'/ usr/local/Cellar/python/2.7.13/bin'中。 – Justin

回答

2

一定出事了你酿造安装。

最新的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 
+0

好吧,当我运行'brew postinstall python'时出现错误。查看原始问题以获取更新。 – Justin

+0

不知道为什么你需要运行它,但它对我来说工作正常。尝试在'〜/ Library/Caches/Homebrew'上删除缓存的文件。 –

0

错误消息对你答案......

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

14

你只需要安装pip这是不是自动安装在macOS Sierra。

运行sudo easy_install pip

+0

像魅力一样工作:-) –

2

我有这个问题,我发现这是解决方案。 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

这将允许您正常点击安装并使用brew版本的python。

现在摆在高塞拉利昂Python中位于/usr/local/bin但出于某种原因,如果你把你的路径/usr/local/bin它会自动指向回/usr/bin,所以这是唯一的解决方案,我已经能够拿出。

Python3没有这个问题,如果你brew install python3和类型which python3你会发现它位于/usr/local/bin/python3

0

这是值得的,在升级到高级雪利山后,我发现我的机器几乎无法用于开发,甚至崩溃了很多次。

关于蟒蛇,我有站点包文件夹内的配股,因此重装没有发挥出来:

$ 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 

希望有所帮助。

相关问题