如何使Mac OS使用Homebrew安装的python [英] How to make Mac OS use the python installed by Homebrew
问题描述
这个问题我已经在网上搜索了一段时间,到目前为止,我所做的是
I have searched online for a while for this question, and what I have done so far is
-
在自制软件中安装了python32
installed python32 in homebrew
更改了我的.bash_profile,并在其中添加了以下行:
changed my .bash_profile and added the following line to it:
export PATH =/usr/local/bin:/usr/local/sbin:〜/bin:$ PATH
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
但是当我关闭终端并重新启动时,我键入哪个python",它仍然会打印:
but when I close the terminal and start again, I type 'which python', it still prints:
/usr/bin/python
/usr/bin/python
并输入'python --version'仍然得到:
and type 'python --version' still got:
Python 2.7.2
Python 2.7.2
我还尝试了以下说明:
brew link --overwrite python
brew link --overwrite python
或尝试通过运行以下指令来删除由homebrew安装的python:
or try to remove python installed by homebrew by running this instruction:
brew删除python
brew remove python
但以上两个说明均导致此错误:
but both of the above two instructions lead to this error:
错误:没有这样的小桶:/usr/local/Cellar/python
Error: No such keg: /usr/local/Cellar/python
任何人都可以帮忙,谢谢
can anybody help, thanks
推荐答案
如果要使用Homebrew安装Python 3:
If you want to install Python 3 using Homebrew:
$ brew install python3
==> Downloading http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2
Already downloaded: /Library/Caches/Homebrew/python3-3.3.0.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/python3/3.3.0 --enable-ipv6 --datarootdir=/usr/local/Cell
==> make
==> make install PYTHONAPPSDIR=/usr/local/Cellar/python3/3.3.0
==> make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python3/3.3.0/share/python3
==> Downloading https://pypi.python.org/packages/source/d/distribute/distribute-0.6.35.tar.gz
Already downloaded: /Library/Caches/Homebrew/distribute-0.6.35.tar.gz
==> /usr/local/Cellar/python3/3.3.0/bin/python3.3 -s setup.py install --force --verbose --install-li
==> Downloading https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/pip-1.3.1.tar.gz
==> /usr/local/Cellar/python3/3.3.0/bin/python3.3 -s setup.py install --force --verbose --install-li
==> Caveats
Homebrew's Python3 framework
/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework
Distribute and Pip have been installed. To update them
pip3 install --upgrade distribute
pip3 install --upgrade pip
To symlink "Idle 3" and the "Python Launcher 3" to ~/Applications
`brew linkapps`
You can install Python packages with
`pip3 install <your_favorite_package>`
They will install into the site-package directory
/usr/local/lib/python3.3/site-packages
Executable python scripts will be put in:
/usr/local/share/python3
so you may want to put "/usr/local/share/python3" in your PATH, too.
See: https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python
安装后更新系统PATH
变量,将下一行添加到~/.bash_profile
Once installed update your system PATH
variable, add the next line to ~/.bash_profile
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
然后:
$ source ~/.bash_profile
现在启动Python:
Now launch Python:
$ python3
Python 3.3.0 (default, Mar 26 2013, 10:01:40)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
您可以检查python3路径:
You can check python3 path:
$ which python3
/usr/local/bin/python3
这篇关于如何使Mac OS使用Homebrew安装的python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!