簡體   English   中英

如何使用brew在Mac OS Sierra上安裝更新的Python?

[英]How to install updated Python on Mac OS Sierra with brew?

我正在運行macOS Sierra版本10.12.2,並且我正在嘗試從預裝的Python 2.7.10系統安裝單獨版本的Python。 我被建議安裝新版本的Python,否則就有可能搞砸系統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

只需更新$PATH變量,指向.bashrc (或) .bash_profile最新版本的Python 2.7.13 ,具體取決於您調用的shell,

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}"

如果您使用Home Brew安裝了Python,請執行以下操作:

brew upgrade python

有時,只是嘗試一個新的shell有幫助。

我剛剛做了同樣的事情,它告訴我python 2.7.10在我的系統上。 但我打開了一個新的外殼並嘗試了,瞧! 這是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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM