LoginSignup
0
0

More than 1 year has passed since last update.

[m1]asdfでバージョン管理を行なったpythonを使うまで[mac]

Posted at

これに続きpython編

前提

  • asdfインストール済み
    • 未インストールの場合、冒頭のnodejsの記事を参照してasdfを導入する

環境

  • MacBook Air (M1, 2020)

python

準備

% asdf plugin-add python

最新安定板の確認/インストール

% asdf latest python
3.9.5
% asdf install python latest

インストールしてあるバージョンの一覧確認

% asdf list
nodejs
  16.2.0
python
  3.9.5

nodeもすでにインストール済みなのでこんな表示になってる

% asdf list python
  3.9.5

とりあえずのプライマリバージョン設定

% asdf global python 3.9.5

有効なバージョンの確認

% asdf current
nodejs          16.2.0          /Users/ユーザー名/.tool-versions
python          3.9.5           /Users/ユーザー名/.tool-versions
% asdf current python
python          3.9.5           /Users/ユーザー名/.tool-versions
% cat ~/.tool-versions
nodejs 16.2.0
python 3.9.5
% python -V
Python 2.7.16

これである

% python -V
Python 2.7.16

現状のpythonの確認

% python -V
Python 2.7.16
% where python
/Users/ユーザー名/.asdf/shims/python
/usr/bin/python
% asdf which python
/Users/ユーザー名/.asdf/installs/python/3.9.5/bin/python

pythonの再設定

% asdf reshim [name] [version]
Recreate shims for version of a package

% asdf reshim python
% python -V
Python 3.9.5
% python2 -V
Python 2.7.16
% python3 -V
Python 3.9.5

適当にファイル作って実行してみる

% touch test.py
test.py
import sys
major = sys.version_info.major
minor = sys.version_info.minor
micro = sys.version_info.micro
output = "hello [Python {}.{}.{}] world".format(major, minor, micro)
print(output)
% python test.py
hello [Python 3.9.5] world
% python2 test.py
hello [Python 2.7.16] world
% python3 test.py
hello [Python 3.9.5] world
0
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
0
0