デジタル推進課

KNIME・Excel Macro・Power Automateなど日々の業務で使用できる自動化ツールを中心に書き綴ります

Python - Mac M1搭載機にPython 3.9.1をインストーラでインストールしてみた

f:id:makkynm:20210111102058p:plain

 

一日1回押していただけると大変応援になります↓ 

にほんブログ村 IT技術ブログへ

 

 

はじめに

Python3.9.1のバージョンからMac M1へのサポートがあるらしい!!

さて、前回Pythonのライブラリがインストールできない!という部分を記事にしました。

degitalization.hatenablog.jp

 

私は勉強のためにPythonを使用しているので正直ARMネイティブにしなくても全然いいのですが、謎の反骨精神からARMネイティブにしようと格闘中です。

今回は、下記の記事を目にして、これならできるかもしれない!というわずかな希望を胸に実験してみたメモです。

www.techradar.com

www.zdnet.com

 

なお、現在experimentalということなので、どこまで動くか実験してみたいところです。

※結論、ライブラリのインストールはいくつか成功して、いくつか失敗してます。最後にまとめてます。

 

Pythonのリリース文章

Python(公式)のリリース文章をそのまま引用します。

公式にM1のサポートを本Versionから行うけど、まだ実験的だから全てが動く保証はないよってことでしょうか。

3.9.1 is the first version of Python to support macOS 11 Big Sur. With Xcode 11 and later it is now possible to build “Universal 2” binaries which work on Apple Silicon. We are providing such an installer as the macos11.0 variant. This installer can be deployed back to older versions, tested down to OS X 10.9. As we are waiting for an updated version of pip, please consider the macos11.0 installer experimental.

www.python.org

 

M1搭載機へのPython 3.9.1のインストール手順

さて、早速インストールしてみたいと思います。

Step1 - 公式サイトからインストーラーをダウンロード

まず公式サイトにアクセスします。Python Release Python 3.9.1 | Python.org

次に、それらしいインストーラをクリックしてダウンロードしていきます。

f:id:makkynm:20210104193157p:plain

インストーラ

f:id:makkynm:20210104193648p:plain

インストーラ ダウンロード完了

Step2 - インストーラを起動

先ほどダウンロードしたインストーラをダブルクリックから起動してみます。

インストーラでどんな文章があったかを掲載しておきます。 

はじめに

This package will install Python 3.9.1 for macOS 10.9 or later.

Python for macOS consists of the Python programming language interpreter and its batteries-included standard library to allow easy access to macOS features. It also includes the Python integrated development environment, IDLE. You can also use the included pip to download and install third-party packages from the Python Package Index.

At the end of this install, click on Install Certificates to install a set of current SSL root certificates.

大切な情報

This package will install Python 3.9.1 for macOS 10.9 or later for the following architecture(s): arm64, x86_64.

Certificate verification and OpenSSL

This package includes its own private copy of OpenSSL 1.1.1.   The trust certificates in system and user keychains managed by the Keychain Access application and the security command line utility are not used as defaults by the Python ssl module.  A sample command script is included in /Applications/Python 3.9 to install a curated bundle of default root certificates from the third-party certifi package (https://pypi.org/project/certifi/).  Double-click on Install Certificates to run it.

The bundled pip has its own default certificate store for verifying download connections.

Using IDLE or other Tk applications 

This package includes its own private version of Tcl/Tk 8.6. It does not use any system-supplied or third-party supplied versions of Tcl/Tk.

Due to new security checks on macOS 10.15 Catalina, when launching IDLE macOS may open a window with a message "Python" would like to access files in your Documents folder.  This is normal as IDLE uses your Documents folder as its default when opening and saving files; you can still choose other locations in the Open and Save file dialog windows.  Click on the OK button to proceed.

macOS 11.0 (Big Sur) and Apple Silicon Mac support [new in 3.9.1]

As of 2020-11, macOS 11.0 (Big Sur) is the latest release of macOS and one of its major features is the support of new Apple Silicon Macs that are based on the ARM64 CPU architecture specification rather than the Intel 64 (x86_64) architecture used previously. There are other changes in Big Sur that affect Python operation regardless of CPU architecture. As of 3.9.1, Python binaries from python.org fully support Big Sur. 

python.org binaries for macOS have been provided via a downloadable installer that supports the Intel 64 architecture on macOS 10.9 and newer.  This installer variant remains the default download for 3.9.1;  it will install and run on all Macs that run macOS 10.9 or later, including 11.0 (Big Sur). This variant should run transparently on new Apple Silicon Macs using Apple's Rosetta 2 emulation. 

 

Beginning with 3.9.1, we also provide a new "universal2" installer variant that provides universal binaries for both ARM64 and Intel 64 architectures and is also supported on all Macs that support macOS 10.9 or later.  Some of the advantages of the new installer variant: native ARM64 code on Apple Silicon Macs should run significantly faster than Rosetta2-emulated code; some operating system functions and options introduced in macOS releases since 10.9 are now exposed when available (primarily in the os module); binary wheels built for use with the current 10.9 variant *should* also work with the new variant; the new installer variant includes Tcl/Tk 8.6.10 rather than 8.6.8.

 

Because of the scope of changes needed to fully support 11.0 and Apple Silicon Macs, the new "universal2" variant should be considered experimental in the 3.9.1 release. You may need to upgrade third-party components, like pip, to later versions once they are released. You may experience differences in behavior in IDLE and other Tk-based applications due to using the newer version of Tk.  As always, if you encounter problems when using this installer variant, please check https://bugs.python.org for existing reports and for opening new issues.

Other changes

For other changes in this release, see the What's new section in the Documentation Set for this release and its Release Notes link at https://www.python.org/downloads/.

気になる文章がありました。。ひとまずやってみましょう。

概要

Congratulations!  Python 3.9.1 for macOS 10.9 or later was successfully installed.

One more thing: to verify the identity of secure network connections, this Python needs a set of SSL root certificates.  You can download and install a current curated set from the Certifi project by double-clicking on the Install Certificates icon in the Finder window.  See the ReadMe file for more information.

 

f:id:makkynm:20210104195518p:plain

インストール完了

インストールが完了しました。自動的にApplicationのフォルダに格納されています。

f:id:makkynm:20210104195931p:plain

インストール完了

 

Step3 - Pythonのバージョンを確認してみる

さて、ターミナルから、Pythonのバージョンを確認してみます。インストーラが完了した後にターミナルを新規で立ち上げて確認してみてください。

Python3.9.1にデフォルトでなっていると思います。

python3 --version

f:id:makkynm:20210104202346p:plain

Pythonのバージョン確認

f:id:makkynm:20210104203419p:plain

Pythonのバージョン確認

ちなみにインストールされている場所を確認してみるとこうなっているようです。

f:id:makkynm:20210104203156p:plain

Python3・Pip3がインストールされている場所

 

以前インストールしたJupyter Notebookではどうだかやってみようと思います。Jupyter Notebookを立ち上げて、下記のようにPythonのバージョンを確認します。

f:id:makkynm:20210104202717p:plain

Jupyter NotebookでPythonのバージョン確認

まだ3.8.2ですね。これはJupyter NotebookがデフォルトでインストールされていたPython3.8.2のPip経由でインストールしたからですかね。再度Jupyter Notebookをインストールしておきます。(省略)

 

VS Codeは下からバージョンを選択すれば、Pythonのバージョンを選べます。 

f:id:makkynm:20210106195500p:plain

 

Step4 - ライブラリをインストールする

さて、本題です。これがやりたかったんです。Pip3でインストールしていきたいと思います。前回は、numpy等のインストールで失敗しました。

Pipを最新バージョンに更新

まずはPipを最新バージョンに更新します。

python3 -m pip install --upgrade pip

f:id:makkynm:20210104204402p:plain

Pipを最新バージョンに更新
便利パッケージpip-reviewをインストール

続いて便利パッケージをインストールしておきます。

f:id:makkynm:20210109102258p:plain

pip-reviewをインストール
Numpy / Pandas / matplotlib / scipy をM1にインストール(失敗)

numpyで試してみます。

f:id:makkynm:20210104204744p:plain

numpyインストール失敗、、
エラーの文章の中に下の文章があったので、再度コマンドを追加して実行してみましたが、ダメでした。

ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly  

 

python3 -m pip install --no-use-pep517 numpy

f:id:makkynm:20210106201955p:plain

numpyインストール失敗

Pandas / matplotlib / scipyも同様にダメでした。

 

selenium / OpenPyXL / beautifulsoup4 / requests / tweepy / wheel をM1にインストール(成功)

成功したものも中にはいくつかありました。

seleniumは成功しました!

f:id:makkynm:20210109100700p:plain

seleniumは成功

OpenPyXLも成功です。でもwheelがインストールされていないからLegacyの使ったって書いてますね、、

f:id:makkynm:20210109101341p:plain

OpenPyXLは成功

怒られたので、wheel、インストールしておきます。

f:id:makkynm:20210109101607p:plain

wheelをインストール

beautifulsoup4もOKです。

f:id:makkynm:20210109101848p:plain

beautifulsoup4をインストール

 

requestsもインストール可能でした。

f:id:makkynm:20210109102600p:plain

requestsもOK

 

tweepyもOK

f:id:makkynm:20210109102743p:plain

tweepyもOK

 

 

まとめ - M1搭載Mac Python ライブラリ インストールできたもの・できなかったもの

さて、色々書いてもあれなので、pip3 でインストールできたもの・できなかったものをまとめて終わろうと思います。

 

使用環境

使用したMacbook Airはこれです。

f:id:makkynm:20210109103735p:plain

 

ライブラリインストール結果

主要なライブラリのインストール結果は下記の通りです。

 

ライブラリ名

結果

バージョン

コメント

便利ツール

pip

20.3.3

 

便利ツール

wheel                     

0.36.2

 

便利ツール

pip-review

1.1.0

 

便利ツール

tqdm

4.55.1

 

便利ツール

joblib

1.0.0

 

便利ツール

jupyter                   

1.0.0

 

便利ツール

jupyterlab

3.0.3

sudoコマンドでInstall

分析系

pandas

×

 

clang: error: the clang compiler does not support 'faltivec'

分析系

numpy

×

 

clang: error: the clang compiler does not support 'faltivec'

分析系

scipy

×

 

clang: error: the clang compiler does not support 'faltivec'

分析系

xlrd

2.0.1

 

分析系

XlsxWriter

1.3.7

 

分析系

openpyxl          

3.0.5

 

画像系

matplotlib

×

 

clang: error: the clang compiler does not support 'faltivec'

画像系

japanize-matplotlib

×

 

clang: error: the clang compiler does not support 'faltivec'

画像系

Pillow

 

The headers or library files could not be found for jpeg,

インストール方法を少し工夫する必要がありそう。

画像系

opencv-python

×

 

clang: error: the clang compiler does not support 'faltivec'

画像系

folium

×

 

 

画像系

plotly

4.14.1

 

画像系

wordcloud

×

 

clang: error: the clang compiler does not support 'faltivec'

スクレイピング

requests

2.25.1

 

スクレイピング

beautifulsoup4

4.9.3

 

スクレイピング

lxml

4.6.2

 

スクレイピング

selenium

3.141.0

 

Web系

Flask

1.1.2

 

Web系

Flask-Bootstrap4

4.0.2 

 

Web系

Django

3.1.5

 

Web系

PyMySQL

1.0.2

 

Web系

tweepy

3.10.0

 

Web系

PyInstaller

4.1

 

 

そのほか、インストール済みのライブラリは下記の通りです。

ライブラリ名

結果

バージョン

altgraph                  

0.17

anyio                     

2.0.2

appnope                   

0.1.2

argon2-cffi               

20.1.0

asgiref                   

3.3.1

async-generator    

1.10

attrs                     

20.3.0

Babel                     

2.9.0

backcall                  

0.2.0

bleach                    

3.2.1

certifi                   

2020.12.5

cffi                      

1.14.4

chardet                   

4.0.0

click                     

7.1.2

decorator                 

4.4.2

defusedxml           

0.6.0

dominate                  

2.6.0

entrypoints               

0.3

et-xmlfile                

1.0.1

idna                      

2.10

ipykernel                 

5.4.2

ipython                   

7.19.0

ipython-genutils     

0.2.0

ipywidgets                

7.6.3

itsdangerous         

1.1.0

jdcal                     

1.4.1

jedi                      

0.17.0

Jinja2                    

2.11.2

joblib                    

1.0.0

json5                     

0.9.5

jsonschema           

3.2.0

jupyter-client            

6.1.10

jupyter-console       

6.2.0

jupyter-core              

4.7.0

jupyter-server        

1.2.1

jupyterlab                

 

jupyterlab-pygments  

0.1.2

jupyterlab-server      

2.1.1

jupyterlab-widgets  

1.0.0

macholib                  

1.14

MarkupSafe        

1.1.1

mistune                   

0.8.4

nbclassic                 

0.2.6

nbclient                  

0.5.1

nbconvert             

6.0.7

nbformat                  

5.0.8

nest-asyncio         

1.4.3

notebook                  

6.1.6

oauthlib                  

3.1.0

openpyxl                  

3.0.5

packaging           

20.8

pandocfilters            

1.4.3

parso                     

0.8.1

pexpect                   

4.8.0

pickleshare               

0.7.5

prometheus-client  

0.9.0

prompt-toolkit      

3.0.10

ptyprocess               

0.7.0

pycparser                 

2.20

Pygments                 

2.7.3

pyinstaller-hooks-contrib 

2020.11

PyMySQL       

1.0.2

pyparsing                 

2.4.7

pyrsistent                

0.17.3

PySocks                   

1.7.1

python-dateutil     

2.8.1

pytz                      

2020.5

pyzmq                     

20.0.0

qtconsole                 

5.0.1

QtPy                      

1.9.0

requests-oauthlib      

1.3.0

retrying                  

1.3.3

Send2Trash         

1.5.0

setuptools                

49.2.1

six                       

1.15.0

sniffio                   

1.2.0

soupsieve                 

2.1

sqlparse                  

0.4.1

terminado           

0.9.2

testpath                  

0.4.4

tornado                   

6.1

traitlets                 

5.0.5

urllib3                   

1.26.2

visitor                   

0.1.3

wcwidth                   

0.2.5

webencodings          

0.5.1

Werkzeug          

1.0.1

widgetsnbextension

3.5.1

pyautogui

 

 

おわりに

結局最新のPythonのバージョンをLocalをInstallしたところで、faltivec 系のライブラリのインストールが対応されていないために追加ライブラリを使用するプログラムは動かないということでした。そろそろnumpy/pandas等のライブラリ入れたいので、Homebrew 等を使用してインストールしようかなーとも思ってます。

ではまた!

degitalization.hatenablog.jp

 

 

余談

Mac M1を購入している方へのおすすめをあげておきます。 

おすすめTypeC変換器: 7 in 1 

私はこちらを購入しました。HDMIVGAがついているので、拡張画面や発表するときには安心ですよね。また、USBポートはもちろん、TypeC、SDカードも含まれているので、これさえあれば最低限カバーできるはずです!

 

TypeC変換器 その2: 10 in 1 

有線のLANケーブルのポートも欲しいという方はこちらをお勧めします。また、USBポートが3つついていることも魅力ですね。

先ほどあげた、SDカード・HDMIVGA・TypeCも含まれているので、これさえあれば充分ですね!

 

Macbook用バック

あんまり傷つけたくないですよね。保護できるカバーも少しスマートに見えそうなものを選びました。

 

 

緊急事態宣言出せれてしまいましたね、、皆さん健康にお過ごしでしょうか。コロナもひどいですが、この寒波、寒すぎじゃないですか、、

私はエアコンガンガンに対応する予定だったのですが、なんと以前エアコンをつけたらくしゃみと鼻水が止まらなくなり、それ以降エアコンをつけずにダウンと毛布で凍えながら生きてました、、そして先日、ついにエアコン掃除を頼んでやっと待ち望んだエアコンライフを過ごしてます!

エアコン掃除って意外と相場高いんですね、でもかなり短時間で汚れ完璧に落としてくれるので最高でした!私はコスパをめちゃめちゃ重視します。今回寒い思いに耐えながら考えに考え抜いて絞りこんだ発注先は「おそうじ本舗」という有名?なところです。

 

エアコン掃除って一番時間かかって、なおかつ綺麗にしきれない面倒臭い場所だと思うんですよねー。厄介なのが、カビがたいてい目に見えないという、、

私の場合、見た目全然汚れてなかったのですが、いざ掃除すると廃液が黒い黒い。こんな風浴びてたのか、そりゃくしゃみ止まらんなという感じでした。業者の人によると、大体皆さん2、3年に1回のペースで頼まれてるみたいです。私はくしゃみが止まらなくなることを基準に動いてましたが、ちょうど2年くらいでした。

流れはこんな感じでした。

  1. Webから申し込み
  2. メール・LINE・SMSのどれかで日程調整
  3. 実際にその日に業者の方が来て30分ほどで作業完了
  4. 振込か現金で支払い

結構スムーズで全然時間取られなかったのが嬉しかったですね!ちょいちょいキャンペーンやっているみたいですし、すぐ終わるので今の時期コロナとは違う原因で風邪ひきたくない方にもおすすめです。よかったらぜひ。

 

 

少しの応援が大変励みになります。

まっきーにOFUSEする

f:id:makkynm:20201219150553p:plain

 

参考リンク