lzma 是python3.3 之后引入的一个官方压缩库,但是在使用时候发现import error
1 | $ python |
日常机器环境oxs+brew+pyenv,一顿找,发现应该是lib的问题,新版lzma 已经合并到xz库里面,安装xz
1 | brew install xz |
pyenv 安装个新的 3.5.6版本测试
1 | pyenv install 3.5.6 |
报错:install failed, “zlib not available” on macOS Mojave
1 | CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 3.5.6 |
1 | $pyenv local 3.5.6 |
仍然报错,思考应该python编译的时候依赖库问题
brew 安装的依赖库都会放在/usr/local/homebrew/Cellar/下面
1 | $ ll /usr/local/homebrew/Cellar/xz/5.2.4/include/ |
通过brew link xz 软连接到/usr/local/homebrew/include/目录下(默认执行)
1 | $ ll /usr/local/homebrew/include/ |grep lzma |
所以
1 | CFLAGS="-I$(xcrun --show-sdk-path)/usr/include -I/usr/local/homebrew/include" pyenv install 3.5.5 |
1 | $pyenv local 3.5.5 |
成功,反思“定位到是python编译的时候依赖库问题”走了弯路,CFLAGS解决zlib时就应该想到
参考
20201225
pyenv macOS Big Sur 11.1安装问题,解决方法:
1 | CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" pyenv install --patch 2.7.15 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1) |