macOS系统内Python多版本共存

参考链接:
https://www.cnhzz.com/pyenv_virtualenv_virtaulenvwrapper/
https://gist.github.com/miminus/671de665a440ef12cafc31e7a97acc89

添加.zshrc 代码

vi ~/.zshrc 编辑文件

if which pyenv > /dev/null; then eval “$(pyenv init -)”; fi
export PYENV_ROOT=/usr/local/var/pyenv

source ~/.zshrc 刷新配置文件

安装python3版本

pyenv install 3.4.0

报错

zipimport.ZipImportError: can’t decompress data; zlib not available

尝试解决办法 安装 zlib
解决方法:xcode-select –install,然后安装命令行工具(即使你安装了xcode)
参考连接:https://segmentfault.com/a/1190000004179057

搞不定了,还是下载安装包吧
下载链接(XZ compressed source tarball)
https://www.python.org/downloads/release/python-349/

tar -zxf Python-3.4.9.tar.xz 解压
cd Python-3.4.9 进入文件夹

安装

./configure
make
make install

查看python3安装位置

MacBook:Python-3.4.9 shen$ which python3
/usr/local/bin/python3

依旧报错

zipimport.ZipImportError: can’t decompress data; zlib not available
make: *** [install] Error 1

按照这个解决尝试

连接:
https://github.com/pyenv/pyenv/wiki/Common-build-problems#build-failed-error-the-python-zlib-extension-was-not-compiled-missing-the-zlib

1
2
3
4
5
6
7
8
9
MacBook:~ shen$ export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig/ >> ~/.p
.p2/ .putty/ .pyenv/ .python_history
MacBook:~ shen$ echo 'export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig/' >> ~/.bash_profile
MacBook:~ shen$ pyenv install 3.5.2
python-build: use openssl from homebrew
python-build: use readline from homebrew
Installing Python-3.5.2...
patching file Lib/venv/scripts/posix/activate.fish
python-build: use readline from homebrew

搞定了 解决了 太棒了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
MacBook:~ shen$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install update
MacBook:~ shen$ Software Update
-bash: Software: command not found
MacBook:~ shen$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
installer: Package name is macOS_SDK_headers_for_macOS_10.14
installer: Installing at base path
installer: The install was successful.
MacBook:~ shen$
MacBook:~ shen$ pyenv install 3.5.2
python-build: use openssl from homebrew
python-build: use readline from homebrew
Installing Python-3.5.2...
patching file Lib/venv/scripts/posix/activate.fish
python-build: use readline from homebrew
Installed Python-3.5.2 to /Users/shen/.pyenv/versions/3.5.2