MacOSでのインストールメモ

Mac OS 10.15.5 (Catalina) での動作確認です.
それぞれの作業を動画でも用意しましたので,そちらも併用して確認してみて下さい.

まず,インストールした直後のまっさらな状態では,python2.7 (2.7.16 default, Apr 17 2020, 18:29:03) のみが入っていて,python3系列は使えません.

ryukoku@virtualMac ~ % python

WARNING: Python 2.7 is not recommended. 
This version is included in macOS for compatibility with legacy software. 
Future versions of macOS will not include Python 2.7. 
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Apr 17 2020, 18:29:03) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

そこで,ターミナルでpython3 と入れてみると,「Xcode(コマンドライン・デベロッパツール)」のインストールを求められますので「インストール」を選んでみます.

ryukoku@virtualMac ~ % python3
xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.

これで,python 3.7.3が入ります.

ryukoku@virtualMac ~ % python3
Python 3.7.3 (default, Apr 24 2020, 18:51:23) 
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Tk のライブラリがpython3.8 用になっているので,python3.7 は実は不要です.
以下でpython3.8を明示してインストールすると,python3.7がなくなり,python3.8になります.
もし,python3.7 が残っている場合は,python3 で3.7が起動しますので,3.8を使うにはpython3.8と入力しましょう.

ついでに,pip のアップデート

sudo pip3 install --upgrade pip

python3.7 だと,うまくいかないので,python3.8 を入れる.
その前にbrewのインストール.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install pyenv
brew install python@3.8
# ここで一回ブラウザを起動し直すことをお勧めします.
zsh
pip3 install -U pylint
pip3 install pillow

あと,tkinter がMac標準(3.8)だとpng が表示できないとかなんとか.
=> この前は無理だったけど,今はうまくいけている….

もし,画像が表示されない場合はPythonのCanvasに画像が表示されないを参考に,PILへの書き換えをします.
加えて,_tkinter.TclError: couldn’t recognize data in image file \”./chap3-back.png\”も参考にしました.

# import 部分に以下を追加
from PIL import Image, ImageTk

#
# ...
#

# 画像の読み込み部分をtkinterからImageTkに置き換えて,fileの引数ではなくImage.openにしてconvert("RGB")を経由する.
# img = tkinter.PhotoImage(file="chap3-back.png")
img = ImageTk.PhotoImage(Image.open("chap3-back.png").convert("RGB"))

とりあえず,上記でchap3.py (Mac用に修正済み)が動作しました.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

*