M1 MacにPyPyをインストールした記録

PyPyのM1Mac向けバージョンがリリースされ、インストールにむちゃくちゃ苦戦したので、記録。

PyPyの入手

ここから躓く。 https://www.pypy.org/download.html ここからダウンロードしろって書いてあるけど

「おめーのPyPyねーから!」と言われ、心がくじける。

http://downloads.python.org/pypy/ からダウンロードできそうなことを知る。

pypy3.8-v7.3.10-macos_arm64.tar.bz2を選びます

pypyのインストール

どうやらhttps://doc.pypy.org/en/latest/build.html を見ながら自分でビルドしなければないっぽい。 このドキュメントに沿って行っていくので、詰まったところまで飛ばして読んでください。

Clone the repository

hg cloneが出てきて、そんなコマンドこのマックには存在しないよと言われて調べる。 ググラビティが低い、いや、私の検索能力が低い。

If you prefer to compile your own PyPy, or if you want to modify it, you will need to obtain a copy of the sources. This can be done either by downloading them from the download page or by checking them out from the repository using mercurial. We suggest using mercurial if you want to access the current development. mercurialをインストールしよう。

mercurialのインストール

どうやらmercurialというツールで、リポジトリのクローンなどが行えるらしい。 brew install mercurialする。 hg clone https://foss.heptapod.net/pypy/pypy pypyどんだけpypy言わすのよ!w

時間かかる

Install build-time dependencies

On Mac OS X: Currently PyPy supports both building on both Apple Silicon (M1, Arm64) and X86_64. You must use an appropriate toolchain for building: either arm64 or x86_64. “Fat” universal2 builds are not supported. Currently tcl/tk is not supported, set export PYPY_PACKAGE_WITHOUTTK=1 when packaging to avoid attempting to build the _tkinter extension library. Most of the build-time dependencies are installed alongside the Developer Tools. openssl still need to be installed for tests, and a brew-provided pypy will speed up translation: xcode-select --install /usr/local/bin/brew install openssl pypy pkg-config After setting this up, translation (described next) will find the libs as expected via pkg-config.

やったーMacのところだけ簡単だーって思ったけど pypy: The x86_64 architecture is required for this software.
のエラーがでて進めない。 なんとpypyをビルドするためにpypyをインストールしなければならないらしい。 それなんて無理ゲ?

unidayoさんのありがたい助言により、Cpythonつかってビルドすることに。

Run the translation

translationがなんのことかわかりませんが(ビルドとどう違うの…?)
推奨されている
pypy ../../rpython/bin/rpython --opt=jit
を行うに当たって、pypyのインストールが必要なので、このコマンドは使えません。 途方に暮れてpypyフォルダを眺めていたところMakefileを発見 あ、これ普通に make
でビルドできるんじゃね?

ここからが地獄だった…

python2がない

まずrpythonはおそらくpython2で書かれており、最新のmacではpython2が抹消されているため、python2をインストールし、pathを通す(しかもpython2ではなくpythonで通す)必要がありました。 これは pyenv install 2.7.18
して .zshrc
export PATH=$PATH:/Users/ainem/.pyenv/versions/2.7.18/bin/
PATHを通せばおk

pycparserがない

pip2 install pycparser
python2用なのに注意

expatがない

これめっちゃ困りました

expatって検索しても出てこないし… https://docs.huihoo.com/pypy/2.5/windows.html#the-expat-xml-parser こいつです

cmake automake autoconf

expatを入れるために brew install cmake
brew install automake
brew install autoconf
しました

やっとビルド

さて、pypyフォルダで make
を実行すればなんかきれいな図形

Build cffi import libraries for the stdlib

ここでM1Macはtkinterが無理らしいので

PYTHONPATH=../.. ./pypy-c ../../lib_pypy/pypy_tools/build_cffi_imports.py

これに--no-tkinter_みたいなオプションをつけなければならない(画像どこかになくしてしまって正確なコマンドがわからない)

Packaging (preparing for installation)

ここはつまづかなかった python pypy/tool/release/package.py --archive-name=pypy-VER-PLATFORM

シンボリックリンクの指定

さて、ここでやっとダウンロードしたものたちの出番 解答したファイルの中から

./bin/
./include/pypy3.8/include
./lib/pypy3.8

というフォルダたちをどこか適当なところ(opt/pypyとかを推奨されている)に置く そしてbinにあるpypy(シンボリックリンク)をいい感じのところに置いて、さらにはPATHを通せば完璧 PATHの通し方、わからん…

めっちゃ怒られる

開発元を検証できない実行ファイルのため、めちゃくちゃ怒られる、というかFinderからじゃないとこの警告を解除できないので実質詰み…

https://mac-tegaki.com/basic-usage/sierra-mac-app-store-permission.html ここでこの記事を見つける なんか危険そうだけどとりあえずこれをしないと実行できないのでやっておく(ここのコマンドは上の記事から調べて、自己責任でお願いします!)

これでPYPY環境のできあがり!!!!!

うーん質問あっても答えられるかわかりませんが、一つの記録として!