1. 程式人生 > 實用技巧 >Mac Big Sur11.0.1 安裝python報錯

Mac Big Sur11.0.1 安裝python報錯

❯ pyenv install 3.6.8
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.8.tar.xz...
-> https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
Installing Python-3.6.8...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 
11.0.1 using python-build 20180424) Inspect or clean up the working tree at /var/folders/bb/0bxy1cy57rb_pxdkvlyst3nh0000gn/T/python-build.20201120103846.92208 Results logged to /var/folders/bb/0bxy1cy57rb_pxdkvlyst3nh0000gn/T/python-build.20201120103846.92208.log Last 10 log lines: struct sf_hdtr sf; ^ ./Modules/posixmodule.c:8210:15: error: implicit declaration of function
'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration] ret = sendfile(in, out, offset, &sbytes, &sf, flags); ^ clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -I. -I./Include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl@1.1
/include -I/Users/ethanyan/.pyenv/versions/3.6.8/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl@1.1/include -I/Users/ethanyan/.pyenv/versions/3.6.8/include -I/usr/local/opt/openssl@1.1/include -DPy_BUILD_CORE -c ./Modules/_codecsmodule.c -o Modules/_codecsmodule.o clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -I. -I./Include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl@1.1/include -I/Users/ethanyan/.pyenv/versions/3.6.8/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl@1.1/include -I/Users/ethanyan/.pyenv/versions/3.6.8/include -I/usr/local/opt/openssl@1.1/include -DPy_BUILD_CORE -c ./Modules/_weakref.c -o Modules/_weakref.o 2 errors generated. make: *** [Modules/posixmodule.o] Error 1 make: *** Waiting for unfinished jobs....

Mac升級新版本之後,原有的開發環境不可用

1. 原有的開發環境安裝了好幾個Python版本;

2. 更新系統之後除自帶的Python2.7之後,Python3環境均不可用;

3. 剛開始執行python3會報錯 images not load,網上的回答都是缺失libZib依賴,然而我的並不是

4. 我開始解除安裝所有的python3環境,準備重新安裝環境依賴;

5. 採用brew install python3安裝成功,預設安裝最高版本python;

6. 此時我準備採用pipenv重新建立虛擬環境,但是高版本的python目前虛擬化不出低版本python;

7. 我又開始採用pyenv這個包管理工具進行python多環境管理;搗騰了大半天才發現Mac11.0.1版本不支援pyenv;

8. 此時已經快要炸了。(後邊已經找到了其他解決方案,文章最底部會有操作過程,但是我用了另一種方式)

9. 採用anaconda包管理工具。具體怎麼操作可以百度。

Step 1 Align command-line tools

Open Xcode-beta.app
Go to Preference > Locations
Select the right version of command-line tools

Step 2 Install python

In this case, I installed 3.8.0. If you want to install a different version, you will need to change the version in the following command.
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 3.8.0 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)