Mac OS Python安装混乱

时间:2018-09-24 17:50:50

标签: python macos python-2.7 pip

我试图开始一个python项目,我需要一些数据科学库,并被指示安装Anaconda。 安装后,我意识到我不想要它,因此我尝试将其卸载。

现在我正在尝试安装带有pip的软件包,但是我想pip尚未安装,或者我的路径现在已经不合时宜了,我很困惑,因为python在多个地方。

/Library/Python中,我有一个2.6和2.7文件夹,都只包含Extras.pth和README

/usr/local/bin中,我有python2 python2-config python2.7 python2.7-config pythonw2 pythonw2.7
这显然是Pipenv环境吗?当我在PyCharm /usr/local/bin/python2.7中创建一个新项目时,它就是要使用的目录。

还有python

/usr/local/opt/python
/usr/loca/opt/python2
/usr/local/Cellar/python/2.7.13_1/

我的问题是,当我想用​​pip安装任何东西时

-bash: pip: command not found

我运行sudo easy_install pip时得到

Searching for pip
Reading https://pypi.python.org/simple/pip/
Download error on https://pypi.python.org/simple/pip/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) -- Some packages may not be found!
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) -- Some packages may not be found!
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')

运行which python会得到/usr/bin/python

所以现在我对哪个目录是python以及如何让pip再次工作感到困惑。

/usr/local/Cellar/python/2.7.13_1/bin/pip的Homebrew安装中,我唯一知道pip存在并起作用的地方

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

这可能需要一些迭代才能回答,但我会尝试。 不幸的是,我的声誉还不允许评论:(

首先,我将检查PATH环境变量:

$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

就我而言,PATH中的第一件事是python.org中的python 3.6,然后是其他标准路径。

我在/Library/Python/2.7/site-packages中还安装了Extras.pth和README,以及其他已安装的软件包。

/ usr / bin / python中的python应该是与OSX一起安装的默认python。

您安装的所有其他python都将位于/ usr / local / bin中。您可以通过完整列出来找出符号链接指向的位置

$ ls -al /usr/local/bin/python*
lrwxr-xr-x  1 username  wheel  38 Jun 21 10:21 /usr/local/bin/python -> ../Cellar/python@2/2.7.15_1/bin/python
lrwxr-xr-x  1 username  wheel  45 Jun 21 10:21 /usr/local/bin/python-config -> ../Cellar/python@2/2.7.15_1/bin/python-config
lrwxr-xr-x  1 username  wheel  39 Jun 21 10:21 /usr/local/bin/python2 -> ../Cellar/python@2/2.7.15_1/bin/python2
lrwxr-xr-x  1 username  wheel  46 Jun 21 10:21 /usr/local/bin/python2-config -> ../Cellar/python@2/2.7.15_1/bin/python2-config
lrwxr-xr-x  1 username  wheel  41 Jun 21 10:21 /usr/local/bin/python2.7 -> ../Cellar/python@2/2.7.15_1/bin/python2.7
lrwxr-xr-x  1 username  wheel  48 Jun 21 10:21 /usr/local/bin/python2.7-config -> ../Cellar/python@2/2.7.15_1/bin/python2.7-config
lrwxr-xr-x  1 root  wheel  69 Aug  6 22:31 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3
lrwxr-xr-x  1 root  wheel  76 Aug  6 22:31 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3-config
lrwxr-xr-x  1 root  wheel  71 Aug  6 22:31 /usr/local/bin/python3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
lrwxr-xr-x  1 root  wheel  78 Aug  6 22:31 /usr/local/bin/python3.6-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6-config
lrwxr-xr-x  1 root  wheel  72 Aug  6 22:31 /usr/local/bin/python3.6m -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m
lrwxr-xr-x  1 root  wheel  79 Aug  6 22:31 /usr/local/bin/python3.6m-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m-config
lrwxr-xr-x  1 username  wheel  39 Jun 21 10:21 /usr/local/bin/pythonw -> ../Cellar/python@2/2.7.15_1/bin/pythonw
lrwxr-xr-x  1 username  wheel  40 Jun 21 10:21 /usr/local/bin/pythonw2 -> ../Cellar/python@2/2.7.15_1/bin/pythonw2
lrwxr-xr-x  1 username  wheel  42 Jun 21 10:21 /usr/local/bin/pythonw2.7 -> ../Cellar/python@2/2.7.15_1/bin/pythonw2.7

就我而言,我已经安装了Homebrew python 2.7.15(以Cellar开头的任何版本)和Python.org 3.6(以/Library/Frameworks开头)

所以...回到您想做的事情。

如果要运行Homebrew python,请在提示符下键入python2。 如果要运行OSX python,请输入python

如果要将Homebrew作为默认名称运行,只需键入python,就必须在/ usr / local / bin中添加符号链接,类似于我清单中的前两行,以便于查找在/ usr / bin之前的路径中(您将覆盖python命令)。

我不确定您的easy_install为何失败,但是which easy_install可能会告诉您,这也仅指向easy_install的OSX python安装版本。

我希望对您有帮助吗?不幸的是,由于我已经安装了pip,因此无法复制您的错误。