目的
M1 Macにpython3.7環境を構築したい
環境
~ ❯ sw_vers
ProductName: macOS
ProductVersion: 12.2.1
BuildVersion: 21D62
~ ❯ sysctl machdep.cpu.brand_string
machdep.cpu.brand_string: Apple M1
背景
- 目的: M1 Macにpython3.7環境を構築したい
- 施策: こちらの記事を参考にpyenvを導入
- 問題:
$ pyenv install 3.7.12
にて以下のエラー発生 - 施策: こちらの記事を参考に
$ xcode-select --install
などを実施 - 問題: 依然として
$ pyenv install 3.7.12
は同様のエラー発生
~ ❯ pyenv install 3.7.12
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.12.tar.xz...
-> https://www.python.org/ftp/python/3.7.12/Python-3.7.12.tar.xz
Installing Python-3.7.12...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
BUILD FAILED (OS X 12.2.1 using python-build 20180424)
Inspect or clean up the working tree at /var/folders/8s/dtsbb4kj5v5dq13thtlh14cc0000gn/T/python-build.20220224123613.31577
Results logged to /var/folders/8s/dtsbb4kj5v5dq13thtlh14cc0000gn/T/python-build.20220224123613.31577.log
Last 10 log lines:
_PyLocale_localeconv in libpython3.7m.a(_localemodule.o)
"_libintl_textdomain", referenced from:
_PyIntl_textdomain in libpython3.7m.a(_localemodule.o)
ld: symbol(s) not found for architecture arm64
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [python.exe] Error 1
make: *** Waiting for unfinished jobs....
make: *** [Programs/_testembed] Error 1
解決方法
- intel x86仕様のhomebrewを使ってpython3.7をインストール
- シンボリックリンクにてpyenvのバージョンフォルダとリンク
実際にteminalにて実行したコードは以下の様.
# Install x86 homebrew
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
alias ibrew="arch -x86_64 /usr/local/bin/brew"
# Install Python 3.7
ibrew install python@3.7
# Add `python` executable (symlink to `python3`)
ln -s python3 "$(ibrew --prefix python@3.7)"/bin/python
# Symlink x86 Python 3.7 into pyenv
ln -s "$(ibrew --prefix python@3.7)" ~/.pyenv/versions/3.7.12
# Check
pyenv local 3.7.12
python3 -V
使用ソフトウェアバージョン
-
/opt/homebrew/bin/brew
: Apple M1仕様のhomebrew -
/usr/local/bin/brew
: Intel x86仕様のhomebrew
~ ❯ pyenv -v
pyenv 2.2.4
~ ❯ /opt/homebrew/bin/brew -v
Homebrew 3.3.16
Homebrew/homebrew-core (git revision 4e9f2fa2945; last commit 2022-02-23)
~ ❯ /usr/local/bin/brew -v
Homebrew 3.3.16
Homebrew/homebrew-core (git revision ff793e4fe51; last commit 2022-02-24)
Homebrew/homebrew-cask (git revision 9303a058be; last commit 2022-02-24)