Mac没有找到Homebrew安装的Python

时间:2018-06-18 16:05:42

标签: python pip homebrew

所以我通过homebrow安装了python。当我brew info python时,我得到了这个:

python: stable 3.6.5 (bottled), devel 3.7.0rc1, HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/3.6.5_1 (5,107 files, 103.0MB) *
  Poured from bottle on 2018-06-18 at 10:15:49
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python.rb
==> Dependencies
Build: pkg-config ✔, sphinx-doc ✘
Required: gdbm ✔, openssl ✔, readline ✔, sqlite ✔, xz ✔
Optional: tcl-tk ✘
==> Options
--with-tcl-tk
    Use Homebrew's Tk instead of macOS Tk (has optional Cocoa and threads support)
--devel
    Install development version 3.7.0rc1
--HEAD
    Install HEAD version
==> Caveats
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python/libexec/bin

If you need Homebrew's Python 2.7 run
  brew install python@2

Pip, setuptools, and wheel have been installed. To update them run
  pip3 install --upgrade pip setuptools wheel

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.6/site-packages

See: https://docs.brew.sh/Homebrew-and-Python

我最终试图做pip3 install numpy,但当我这样做时,我收到了这样的信息:

-bash: pip3: command not found

pip install numpy似乎指向Apple默认的2.7 python版本:

Requirement already satisfied: numpy in /Library/Python/2.7/site-packages (1.14.5)

所以问题似乎出现在.bash_profile which python/usr/bin/python。{/ p>

以下是这样的:

export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/Cellar/python/3.6.5_1/bin:$PATH

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

export PATH=$PATH:/Users/thammond/Library/Android/sdk/platform-tools

###########
export PATH=/usr/local/Cellar/postgresql\@9.6/9.6.6/bin:$PATH

###########

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

我确认/usr/local/列在顶部,并尝试添加export PATH=/usr/local/Cellar/python/3.6.5_1/bin:$PATH

但它仍然发现错误的python。我出错了什么想法?

编辑:

当我运行python3 -m ensurepip --upgrade时,我看到了这一点:

Requirement already up-to-date: setuptools in ./Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Requirement already up-to-date: pip in ./Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages

当我运行python3 -m ensurepip -vvv -U时,我明白了:

Ignoring indexes: https://pypi.python.org/simple
0 location(s) to search for versions of setuptools:
Skipping link /var/folders/7d/xvqc5yxs10n6206lytrbs9wm0000gn/T/tmpk6_9t6c2 (from -f); not a file
Skipping link file:///private/var/folders/7d/xvqc5yxs10n6206lytrbs9wm0000gn/T/tmpk6_9t6c2/pip-9.0.3-py2.py3-none-any.whl; wrong project name (not setuptools)
Found link file:///private/var/folders/7d/xvqc5yxs10n6206lytrbs9wm0000gn/T/tmpk6_9t6c2/setuptools-39.0.1-py2.py3-none-any.whl, version: 39.0.1
Local files found: /private/var/folders/7d/xvqc5yxs10n6206lytrbs9wm0000gn/T/tmpk6_9t6c2/setuptools-39.0.1-py2.py3-none-any.whl
Installed version (39.2.0) is most up-to-date (past versions: 39.0.1)
Requirement already up-to-date: setuptools in ./Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
0 location(s) to search for versions of pip:
Found link file:///private/var/folders/7d/xvqc5yxs10n6206lytrbs9wm0000gn/T/tmpk6_9t6c2/pip-9.0.3-py2.py3-none-any.whl, version: 9.0.3
Skipping link file:///private/var/folders/7d/xvqc5yxs10n6206lytrbs9wm0000gn/T/tmpk6_9t6c2/setuptools-39.0.1-py2.py3-none-any.whl; wrong project name (not pip)
Local files found: /private/var/folders/7d/xvqc5yxs10n6206lytrbs9wm0000gn/T/tmpk6_9t6c2/pip-9.0.3-py2.py3-none-any.whl
Installed version (10.0.1) is most up-to-date (past versions: 9.0.3)
Requirement already up-to-date: pip in ./Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Cleaning up...

当我使用finder查看/usr/local/Cellar/python/3.6.5_1/bin/时,我看不到pip / pip3文件。

2 个答案:

答案 0 :(得分:1)

您是否尝试调用/usr/local/Cellar/python3/3.6.5_1/bin/pip3?如果它有效,则意味着pip安装已成功完成,并且您的bashfile将出错。但是,bash文件看起来很正常。

您确认pip3中有/usr/local/Cellar/python3/3.6.5_1/bin/吗? 如果它不存在,则首先不安装pip

this page ("pip3 not installed with python 3.4.2 #33897")似乎有同样的问题 "pip3 not installed with python 3.4.2 #33897"的提问者通过删除/private/var/folders/hy/l_6wd1ps0nz835v4g41zhhtr0000gn/T/pip_build最终解决了这个问题 可能是因为Brew未能完成pip安装。

首先,要引导pip安装程序,请点击python3 -m ensurepip --upgradepython -m ensurepip。 如果它不起作用,请尝试点击python3 -m ensurepip -vvv -U并告诉它说什么。

答案 1 :(得分:1)

我不确定为什么它这次工作但是只是为了踢我决定再次从homebrew卸载并重新安装python但是这次它正常工作并且pip3安装正确且有效。

brew uninstall python3
brew install python3

现在我可以运行pip3 install numpy --user