LoginSignup
1
0

Macの初期設定-Pythonの導入とtkinterの設定

Posted at

はじめに

Macの初期化をしたので最初のHomebrewとanyenv,pyenvのインストールの仕方を残しておく。

目次

  1. Homebrew
  2. anyenv

#環境・バージョン

  • macOS BigSur ver11.3
  • Python 3.9.4
  • anyenv 1.1.2
  • pyenv 1.2.26

1.Homebrew

ここの記事を参考にHomebrewのインストールを行う。

2.anyenv,pyenv,python,tkinter

ここの記事を参考にanyenvとpyenvを使ってpythonをインストールを行うが、このままではtkinterが8.5verのまま呼び出されてしまい表記ミスが多々あるのでpythonインストールの前にここの記事を参考にtcl-tkとpythonのインストールを行う。
pyenvのインストールが下記のスクリプトでtcl-tkのインストールをする。

brew install tcl-tk

インストール完了後下記のような設定をするように指示されるので従う。

If you need to have tcl-tk first in your PATH run:
  echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> /Users/myname/.bash_profile

For compilers to find tcl-tk you may need to set:
  export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
  export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"

export ~で書かれている部分をコピーして以下のスクリプトでbashへの書き込みが行えるので設定後:wqで編集を終了する。

vi .bash_profile

その後pythonのインストールを行うが以下の記述を追記する。

PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I/usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl8.6 -ltk8.6'" pyenv install 3.9.4

これはbrewでインストールしたtcl-tkが8.6なのに対してpyenvが8.5を使用するところをオプションで8.6で行うようにしている。
下記の二つのスクリプトを実行しtkinterのバージョンが8.6になっている事を確認する。

pyenv global 3.9.4
python -m tkinter

1
0
0

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
1
0