安裝背景
Mac 10.15.2,該版本自帶python2.7(默認(rèn)),python3.7。然而,本人內(nèi)心深處總想用最新的python版本。但途中遇到很多麻煩,現(xiàn)已解決,操作如下。
首先,我們需要在系統(tǒng)中安裝pyenv,建議修改brew為國內(nèi)源。
brew install pyenv
pyenv --version //pyenv 1.2.15
本人的pyenv為1.2.15。默認(rèn)情況下,下載python3.8.0走的是python官網(wǎng)提供的ftp。但事實(shí)證明,每次只能下載1/4就會掛掉(本人用瀏覽器按照目錄下的地址下載到1/4停止)。所以,為保證我們可以用pyenv下載到python3.8.0,需要先修改pyenv的下載地址。
cd ~/.pyenv/plugins/python-build/share/python-build
ls
在這里你會看到文件和pyenv install --list一樣的列表。我看到這個(gè)的時(shí)候都興奮了,要知道網(wǎng)上都是什么鏈接地址啊,都找不到這里。
執(zhí)行vi 3.8.1,打開文件如下:
#require_gcc
prefer_openssl11
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL=1
install_package "openssl-1.1.0j" "https://www.openssl.org/source/openssl-1.1.0j.tar.gz#31bec6c203ce1a8e93d5994f4ed304c63ccf07676118b6634edded12ad1b3246" m ac_openssl --if has_broken_mac_openssl
install_package "readline-8.0" "https://ftpmirror.gnu.org/readline/readline-8.0.tar.gz#e339f51971478d369f8a053a330a190781acb9864cf4c541060f12078948e461" m ac_readline --if has_broken_mac_readline
if has_tar_xz_support; then
install_package "Python-3.8.1" "https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tar.xz#75894117f6db7051c1b34f37410168844bbb357c139a8a10a352e9bf 8be594e8" ldflags_dirs standard verify_py38 copy_python_gdb ensurepip
else
install_package "Python-3.8.1" "https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz#c7cfa39a43b994621b245e029769e9126caa2a93571cee2e743b213cceac35f b" ldflags_dirs standard verify_py38 copy_python_gdb ensurepip
fi
修改文件的if下執(zhí)行語句的地址為如下
#require_gcc
prefer_openssl11
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL=1
install_package "openssl-1.1.0j" "https://www.openssl.org/source/openssl-1.1.0j.tar.gz#31bec6c203ce1a8e93d5994f4ed304c63ccf07676118b6634edded12ad1b3246" m ac_openssl --if has_broken_mac_openssl
install_package "readline-8.0" "https://ftpmirror.gnu.org/readline/readline-8.0.tar.gz#e339f51971478d369f8a053a330a190781acb9864cf4c541060f12078948e461" m ac_readline --if has_broken_mac_readline
if has_tar_xz_support; then
install_package "Python-3.8.1" "https://npm.taobao.org/mirrors/python/3.8.1/Python-3.8.1.tar.xz#75894117f6db7051c1b34f37410168844bbb357c139a8a10a352e9bf 8be594e8" ldflags_dirs standard verify_py38 copy_python_gdb ensurepip
else
install_package "Python-3.8.1" "https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz#c7cfa39a43b994621b245e029769e9126caa2a93571cee2e743b213cceac35f b" ldflags_dirs standard verify_py38 copy_python_gdb ensurepip
fi
之后正常執(zhí)行pyenv install 3.8.1,不到一分鐘就安裝好了。。。