2017-01-14 257 views
3

我正在運行macOS Sierra版本10.12.2,並試圖從預裝Python 2.7.10的系統安裝單獨版本的Python。我被建議安裝一個新版本的Python,否則可能會導致系統Python安裝失敗。如何使用brew在Mac OS Sierra上安裝更新的Python?

我使用brew安裝了Python 2.7.13:

brew install python 

但是,我還是終端默認爲系統安裝

$ python 
Python 2.7.10 (default, Jul 30 2016, 19:40:32) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> 

什麼是安裝更新(非的首選方式 - 系統)版本的Python 2.7,並讓操作系統識別並默認使用新的(2.7.13)版本?

編輯:

當我更新.bash_profile文件,下面,我開始了在bash終端時遇到錯誤。

PATH="/usr/local/Cellar/python/2.7.13/bin:${PATH}" 
export "$PATH" 

這是錯誤我收到:

-bash: export: `/usr/local/Cellar/python/2.7.13/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin': not a valid identifier 

回答

3

剛剛更新$PATH變量指向的Python 2.7.13最新版本.bashrc(或).bash_profile取決於要調用的外殼,

export PATH="/path/to/your/python2.7.13/bin:${PATH}" 

即類似/Library/Frameworks/Python.framework/Versions/,即

export PATH="/Library/Frameworks/Python.framework/Versions/2.7.13/bin:${PATH}" 
+1

貌似'brew'在'的/ usr /本地/地窖/蟒/ 2.7.13/bin中/ python2.7'安裝蟒 – Borealis

-2

有時,只是嘗試在新的外殼有幫助。

我剛剛做了同樣的事情,它告訴我python 2.7.10在我的系統上。但我打開了一個新的shell並嘗試,瞧!這是python的正確版本。

$ brew install python 
==> Downloading https://homebrew.bintray.com/bottles/python-2.7.13.sierra.bottle.1.tar.gz 
Already downloaded: /Users/sptamhan/Library/Caches/Homebrew/python-2.7.13.sierra.bottle.1.tar.gz 
==> Pouring python-2.7.13.sierra.bottle.1.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.13/bin --install-lib=/usr/local/lib/python2.7/site-packages 
==> /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.13/bin --install-lib=/usr/local/lib/python2.7/site-packages 
==> /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.13/bin --install-lib=/usr/local/lib/python2.7/site-packages 
==> 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: http://docs.brew.sh/Homebrew-and-Python.html 
==> Summary 
    /usr/local/Cellar/python/2.7.13: 3,526 files, 48MB 
$ python -V 
Python 2.7.10 

在一個新的終端:

$ python -V 
Python 2.7.13