在使用Python进行版本控制之前,我使用了asdf [mac]
接下来是 Python 部分。
前提 tí)
-
- 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
由于节点已经安装完毕,所以才会出现这样的显示。
% 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 python
% python -V
Python 3.9.5
% python2 -V
Python 2.7.16
% python3 -V
Python 3.9.5
随便创建一个文件并尝试运行。
% touch 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