折腾:
【未解决】Win中VMWare中macOS初始化开发环境
期间,继续去安装Python 3
然后去找找之前自己的mac中安装python 3的帖子参考
【已解决】Mac中安装Python
【已解决】Mac中安装最新版的Python3
去试试
先安装brew:
【已解决】Win中VMWare中macOS虚拟机中安装homebrew
再去用brew安装pyenv
brew install pyenv
log
crifanlideMac:homebrew crifanli$ brew install pyenv ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/autoconf-2.69.mojave.bottle.4.tar.gz ######################################################################## 100.0% ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/openssl%401.1-1.1.1g.mojave.bottle.tar.gz ######################################################################## 100.0% ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/pkg-config-0.29.2_3.mojave.bottle.tar.gz ######################################################################## 100.0% ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/readline-8.0.4.mojave.bottle.tar.gz ######################################################################## 100.0% ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/pyenv-1.2.19.mojave.bottle.tar.gz ######################################################################## 100.0% ==> Installing dependencies for pyenv: autoconf, openssl@1.1, pkg-config and readline ==> Installing pyenv dependency: autoconf ==> Pouring autoconf-2.69.mojave.bottle.4.tar.gz ==> Caveats Emacs Lisp files have been installed to: /usr/local/share/emacs/site-lisp/autoconf ==> Summary �� /usr/local/Cellar/autoconf/2.69: 71 files, 3.0MB ==> Installing pyenv dependency: openssl@1.1 ==> Pouring openssl@1.1-1.1.1g.mojave.bottle.tar.gz ==> Caveats A CA file has been bootstrapped using certificates from the system keychain. To add additional certificates, place .pem files in /usr/local/etc/openssl@1.1/certs and run /usr/local/opt/openssl@1.1/bin/c_rehash openssl@1.1 is keg-only, which means it was not symlinked into /usr/local, because macOS provides LibreSSL. If you need to have openssl@1.1 first in your PATH run: echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> /Users/crifanli/.bash_profile For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" ==> Summary �� /usr/local/Cellar/openssl@1.1/1.1.1g: 8,059 files, 18MB ==> Installing pyenv dependency: pkg-config ==> Pouring pkg-config-0.29.2_3.mojave.bottle.tar.gz �� /usr/local/Cellar/pkg-config/0.29.2_3: 11 files, 623.6KB ==> Installing pyenv dependency: readline ==> Pouring readline-8.0.4.mojave.bottle.tar.gz ==> Caveats readline is keg-only, which means it was not symlinked into /usr/local, because macOS provides BSD libedit. For compilers to find readline you may need to set: export LDFLAGS="-L/usr/local/opt/readline/lib" export CPPFLAGS="-I/usr/local/opt/readline/include" For pkg-config to find readline you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig" ==> Summary �� /usr/local/Cellar/readline/8.0.4: 48 files, 1.5MB ==> Installing pyenv ==> Pouring pyenv-1.2.19.mojave.bottle.tar.gz �� /usr/local/Cellar/pyenv/1.2.19: 704 files, 2.5MB ==> Caveats ==> autoconf Emacs Lisp files have been installed to: /usr/local/share/emacs/site-lisp/autoconf ==> openssl@1.1 A CA file has been bootstrapped using certificates from the system keychain. To add additional certificates, place .pem files in /usr/local/etc/openssl@1.1/certs and run /usr/local/opt/openssl@1.1/bin/c_rehash openssl@1.1 is keg-only, which means it was not symlinked into /usr/local, because macOS provides LibreSSL. If you need to have openssl@1.1 first in your PATH run: echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> /Users/crifanli/.bash_profile For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" For pkg-config to find openssl@1.1 you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig" ==> readline readline is keg-only, which means it was not symlinked into /usr/local, because macOS provides BSD libedit. For compilers to find readline you may need to set: export LDFLAGS="-L/usr/local/opt/readline/lib" export CPPFLAGS="-I/usr/local/opt/readline/include" For pkg-config to find readline you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"
以及:
以为是
pyenv versions
看看当前有哪些python 3的版本,比如3.8.0
实际是
pyenv install --list
log
$ pyenv install --list Available versions: 2.1.3 2.2.3 2.3.7 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.6.6 2.6.7 2.6.8 2.6.9 2.7.0 2.7-dev 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.15 2.7.16 2.7.17 2.7.18 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4-dev 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.4.10 3.5.0 3.5-dev 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6-dev 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.6.10 3.7.0 3.7-dev 3.7.1 3.7.2 3.7.3 3.7.4 3.7.5 3.7.6 3.7.7 3.8.0 3.8-dev 3.8.1 3.8.2 3.8.3 3.9.0b3 3.9-dev 3.10-dev 。。。
最新稳定版是:3.8.3
再去用pyenv安装最新版python 3.8.3
pyenv install 3.8.3
log
crifanlideMac:homebrew crifanli$ pyenv install 3.8.3 python-build: use openssl@1.1 from homebrew python-build: use readline from homebrew Downloading Python-3.8.3.tar.xz... -> https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz Installing Python-3.8.3... python-build: use readline from homebrew python-build: use zlib from xcode sdk
然后等待很长时间
过了会,就好了:
Installed Python-3.8.3 to /Users/crifanli/.pyenv/versions/3.8.3
再去设置全局版本是3.8.3
pyenv global 3.8.3
log
crifanlideMac:homebrew crifanli$ pyenv version system (set by /Users/crifanli/.pyenv/version) crifanlideMac:homebrew crifanli$ pyenv versions * system (set by /Users/crifanli/.pyenv/version) 3.8.3 crifanlideMac:homebrew crifanli$ python --version Python 2.7.10 crifanlideMac:homebrew crifanli$ which python /usr/bin/python crifanlideMac:homebrew crifanli$ pyenv global 3.8.3
再去更新到启动脚本中
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
log
crifanlideMac:homebrew crifanli$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile crifanlideMac:homebrew crifanli$ cat ~/.bash_ .bash_history .bash_profile .bash_sessions/ crifanlideMac:homebrew crifanli$ cat ~/.bash_profile export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init -)" fi
然后重新启动一个terminal终端,看看版本是否有变化
Last login: Fri Jun 19 02:14:28 on ttys002 crifanlideMac:homebrew crifanli$ which python /Users/crifanli/.pyenv/shims/python crifanlideMac:homebrew crifanli$ python --version Python 3.8.3 crifanlideMac:homebrew crifanli$
版本的确变成了我们要的最新的3.8.3了

至此,就算安装完毕了。
后记:再去看看pip版本
crifanlideMac:homebrew crifanli$ pip3 --version pip 19.2.3 from /Users/crifanli/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pip (python 3.8)
【总结】
Win中VMWare的macOS中安装最新版Python:
(1)macOS中安装homebrew
正常情况下,直接用homebrew官网的一句命令:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
即可。
但是此处遇到一些问题,所以建议用:
【已解决】Win中VMWare中macOS虚拟机中安装homebrew
总结的步骤去安装。
(2)用brew安装,用来管理多个Python版本的工具:pyenv
brew install pyenv
(3)用pyenv安装最新版的(比如3.8.3)的python 3
pyenv install 3.8.3
其中,最新的稳定版的Python 3,可以通过:
pyenv install --list
查看到具体的版本号。
(4)收尾:设置python 3为全局版本 + 加到启动脚本中
最后再去:
把Python 3设置为全局版本
pyenv global 3.8.3
然后再去把pyenv的设置全局版本的动作,加到macOS启动脚本中
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
注:根据你的情况,把~/.bash_profile换成你的启动脚本,比如~/.bashrc、~/.zshrc等,即可。
转载请注明:在路上 » 【已解决】Win的VMWare的macOS中安装Python3