2017-07-18 49 views
5

我需要使用Python的Homebrew版本而不是系統版本的Python。我有一個乾淨的安裝macOS Sierra(10.12.5)。安裝自制Python和鏈接

我首先安裝了自制軟件,然後使用nano ~/.bash_profile更新了~/.bash_profile。 然後,我添加到這個文件中:

# Homebrew 
export PATH=/usr/local/bin:$PATH 

然後,我需要手動源~/.bash_profile文件,以確保更改已使用source ~/.bash_profile重新加載。

我安裝使用brew install python Python和嘗試使用brew linkapps python

輸出是這個鏈接:

Warning: Already linked: /usr/local/Cellar/python/2.7.13_1 
To relink: brew unlink python && brew link python 
Gautams-Air:~ gautam$ which python 
/usr/bin/python 
Gautams-Air:~ gautam$ python -V 
Python 2.7.10 
Gautams-Air:~ gautam$ brew linkapps python 
Warning: brew linkapps has been deprecated and will eventually be removed! 

Unfortunately brew linkapps cannot behave nicely with e.g. Spotlight using 
either aliases or symlinks and Homebrew formulae do not build "proper" .app 
bundles that can be relocated. Instead, please consider using brew cask and 
migrate formulae using .app's to casks. 
Linking: /usr/local/opt/python/IDLE.app 
Linking: /usr/local/opt/python/Python Launcher.app 
Linked 2 apps to /Applications` 

使用which python輸出是: /usr/bin/python

它應該是:/usr/local/bin/python

我也試過使用:brew unlink python && brew link python

而且使用python -V它顯示Python 2.7.10雖然目前的版本是家釀Python 2.7.13

我如何使用Python的家釀版本,而不是Python中的系統版本? - 我該如何做鏈接?

使用: MacOS的塞拉(10.12.5)

+0

[在OS X上使用Python與自制軟件](http://stackoverflow.com/q/25441252) – jww

回答

8

由於對python2開始2.7.13_1版本家釀配方在最近的變化,自制不再創建python以家釀版本的符號鏈接。

相反,它只安裝和符號鏈接python2。您將需要採取額外的步驟來使用它,而不是系統版本的Python。

請參閱此軟件包信息中的「警告」部分。下面是一個示例,但請注意,要導出的實際PATH已生成,並且可能在您的計算機上有所不同。

$ brew info python2 

... snip ... 

=> Caveats 
This formula installs a python2 executable to /usr/local/bin. 
If you wish to have this formula's python executable in your PATH then add 
the following to ~/.bash_profile: 
    export PATH="<... some path ...>:$PATH" 

... snip ... 

編輯:家釀在他們recent release notes更多地談到這一變化。