5
2

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.

MacでPython3の環境構築

Posted at

はじめに

MacBookを新しく購入したので、Python3を学習しようと思いました。
インストールからPATHを通すまで備忘録としてまとめています。

開発環境

OS: macOS Monterey(バージョン 12.2.1)
チップ: Apple M1

Python3のインストール

MacではデフォルトでPythonが入っています。

terminal
% python -V
Python 2.7.18

Pythonの2系はサポートが終了しており、現在は3系が主流であると何かの記事で見ました。
ですので、Python3をインストールします。

Pythonの公式
上記公式サイトから今回はPython 3.11.5を選択します。
(2023.9月時点)

インストーラがダウンロードされたらダブルクリックして進め、インストールを完了させます。

Python3のPATHを通す

.zshrcにPython3のパスを追加していきます。

terminal
$ vi ~/.zshrc
~/.zshrc
# ◯.△.□には、インストールしたpythonのversionを記述する
# export PYTHON_HOME="/Library/Frameworks/Python.framework/Version/◯.△.□/bin"
export PYTHON_HOME="/Library/Frameworks/Python.framework/Version/3.11.5/bin"
export PATH="$PYTHON_HOME:$PATH"

# pythonコマンドでpython3が起動するように
alias python='python3'
alias pip='pip3'

ターミナルを再起動させたら設定完了です!

動作確認

terminal
% python -V
Python 3.11.5
terminal
% python
Python 3.11.5 (v3.11.5:cce6ba91b3, Aug 24 2023, 10:50:31) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

お疲れ様でした!

5
2
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?