Python 在 macOS Sierra 上安装 pip
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41233594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing pip on macOS Sierra
提问by Justin
I've been trying to install pip on macOS sierra via brew, but every time it completes without installing the binaries in /usr/local/Cellar/python/2.7.13/bin
.
我一直在尝试通过 brew 在 macOS sierra 上安装 pip,但每次它完成时都没有在/usr/local/Cellar/python/2.7.13/bin
.
I've tried:
我试过了:
MacBook-Pro ? brew reinstall python
then:
然后:
MacBook-Pro ? ~ which pip
pip not found
I found the path to python, which is /usr/local/Cellar/python/2.7.13/bin
but no binary for pip there.
我找到了 python 的路径,/usr/local/Cellar/python/2.7.13/bin
但那里没有 pip 的二进制文件。
I also tried the easy_install
approach:
我也尝试了以下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:
更新:
When I run brew postinstall python
I am getting the following error:
当我运行时,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
回答by julien bouteloup
You just need to install pip
which is not automatically installed in macOS Sierra.
您只需要安装pip
macOS Sierra 中未自动安装的那个。
Run sudo easy_install pip
跑 sudo easy_install pip
回答by Mohammed Safeer
For Mac OS Sierra, cannot install pip via easy_install
since there is a problem with TLS Version, Installed Open-SSL version won't support TLS 1.2
对于 Mac OS Sierra,无法安装 pip via,easy_install
因为 TLS 版本有问题,安装的 Open-SSL 版本将不支持 TLS 1.2
So install pip using curl as follows,
所以使用 curl 安装 pip 如下,
curl https://bootstrap.pypa.io/get-pip.py | sudo python
回答by Shane
OK gang, lots of these answers where helpful but none of them got me to the finish line. I am running High Sierra 10.13.4. The problem as documented above is that Brew installs pip in the /usr/local/bin
directory but Python is in /usr/bin
(although as Carl said, Python3 correctly goes to /usr/local/bin
).
好吧,这些答案中有很多有用,但没有一个让我到达终点。我正在运行 High Sierra 10.13.4。上面记录的问题是 Brew 在/usr/local/bin
目录中安装了 pip但 Python 在其中/usr/bin
(尽管正如 Carl 所说,Python3 正确地转到了/usr/local/bin
)。
My immediate use case is related to getting the Postgres BigSQLpackage to install.
我的直接用例与安装Postgres BigSQL包有关。
The steps I took are as follows:
我采取的步骤如下:
- Clear out the brew cache
$ rm -rf ~/Library/Caches/Homebrew
- Clear out the site-packages
$ sudo rm -rf /usr/local/lib/python2.7/site-packages
- Reinstall Python
$ brew reinstall python
This pulls downpython-3.5.6.high_sierra
and put it in/usr/local/bin/python3
- But
which python
still shows/usr/bin/python
- The solutionis to run
brew install python@2
which pulls down[email protected]_3.high_sierra
- Now
which python
shows the correct path/usr/local/bin/python
which is also where all your pip stuff is installed, so now pip will work. - Of course if you have not installed the latest version of pip you should do that too with
sudo pip install --upgrade pip
- 清除 brew 缓存
$ rm -rf ~/Library/Caches/Homebrew
- 清除站点包
$ sudo rm -rf /usr/local/lib/python2.7/site-packages
- 重装Python
$ brew reinstall python
这个拉下来python-3.5.6.high_sierra
放进去/usr/local/bin/python3
- 但是
which python
还是显示/usr/bin/python
- 该解决方案是运行
brew install python@2
其拉低[email protected]_3.high_sierra
- 现在
which python
显示正确的路径/usr/local/bin/python
,这也是你所有 pip 东西的安装位置,所以现在 pip 可以工作了。 - 当然,如果你还没有安装最新版本的 pip 你也应该这样做
sudo pip install --upgrade pip
回答by OneCricketeer
Something must be wrong with your brew installation.
您的 brew 安装一定有问题。
Latest macOS version.
最新的 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
And it definitely exists.
而且它绝对存在。
~/ 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
回答by ajabdelaziz
I had this issue and I found this to be the solution. BTW pip isn't installed via brew. It comes with python and python virtualenvs.
我遇到了这个问题,我发现这是解决方案。顺便说一句,pip 不是通过 brew 安装的。它带有 python 和 python virtualenvs。
if you type which python
without brew install python
you'll get the location in /usr/bin/python
. That is the system python which we don't want to develop with.
如果你which python
不输入,brew install python
你会得到位置/usr/bin/python
。那是我们不想开发的系统python。
So i took the following steps.
1) brew install python
2) export PATH="/usr/local/opt/python/libexec/bin:$PATH"
place that in your ~/.bash_profile
3) source ~/.bash_profile
in your terminal
4) type which python
and that should have changed the location to /usr/local/opt/python/libexec/bin/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
.
This will allow you to pip install normally and use the brew version of python.
这将允许您正常 pip install 并使用 python 的 brew 版本。
Now before high sierra python used to be located in /usr/local/bin
but for some reason if you place /usr/local/bin
in your paths it automatically points back to /usr/bin
, so this is the only solution I have been able to come up with.
现在以前高山脉蟒蛇曾经位于/usr/local/bin
但由于某种原因,如果您将其放置/usr/local/bin
在路径中,它会自动指向回/usr/bin
,所以这是我能够提出的唯一解决方案。
Python3 does not have this issue, if you brew install python3
and type which python3
you'll see that it's located in /usr/local/bin/python3
.
Python3 没有这个问题,如果你brew install python3
输入,which python3
你会看到它位于/usr/local/bin/python3
.
回答by 2075
For what it's worth, after upgrading to high sierra I found my machine pretty much unusable for development, even crashing plenty of times.
值得一提的是,在升级到高山脉后,我发现我的机器几乎无法用于开发,甚至多次崩溃。
Regarding python, i had a rights issue inside the site-packages folder, therefore the reinstall did not work out:
关于 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
...
So to fix it, I completely removed the site-packages:
所以为了修复它,我完全删除了站点包:
$ sudo rm -rf /usr/local/lib/python2.7/site-packages
With this, reinstalling python2, and having a working pip2 again, worked like a charm:
有了这个,重新安装 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
Hope that helps.
希望有帮助。
回答by Carl Russmann
The error message has the answer for you...
错误消息为您提供了答案...
Remove /Users/justin/.venvburrito/lib/python/distribute-0.6.35-py2.7.egg/
and run brew reinstall python
. setuptools
is the wrong version.
删除/Users/justin/.venvburrito/lib/python/distribute-0.6.35-py2.7.egg/
并运行brew reinstall python
。setuptools
是错误的版本。