2016-12-20 304 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 

希望有所幫助。

相關問題