5
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

M1 Macのためのpython3.9未満の環境構築

Last updated at Posted at 2022-02-24

目的

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

背景

  1. 目的: M1 Macにpython3.7環境を構築したい
  2. 施策: こちらの記事を参考にpyenvを導入
  3. 問題: $ pyenv install 3.7.12にて以下のエラー発生
  4. 施策: こちらの記事を参考に$ xcode-select --installなどを実施
  5. 問題: 依然として$ 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

解決方法

  1. intel x86仕様のhomebrewを使ってpython3.7をインストール
  2. シンボリックリンクにて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)

参考

5
12
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?