Python 3.x 語法常與 Python 2.x 不相容,
所以Python的windows安裝檔,從3.3開始多了Python launcher可安裝,
Python launcher 可方便選擇使用哪個版本的Python來執行。
安裝時有勾選安裝「py launcher」即會安裝Python launcher,
安裝後可於命令列操作。
查看 Python launcher 指令說明
>py -h Python Launcher for Windows Version 3.9.6150.1013 usage: py [launcher-args] [python-args] [script [script-args]] .....
列出安裝的所有Python版本,有「*」星號的是預設版本
>py -0 Installed Pythons found by py Launcher for Windows -3.9-64 * -3.9-32 -2.7-64
列出各版本Python安裝的路徑
>py -0p Installed Pythons found by py Launcher for Windows -3.9-64 C:\Program Files\Python39\python.exe * -3.9-32 C:\Users\user\AppData\Local\Programs\Python\Python39-32\python.exe -2.7-64 C:\Users\user\.windows-build-tools\python27\python.exe
執行預設版本
>py Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
執行指定版本
>py -2 Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
執行指定版本,且為32-bit的版本
>py -3-32 Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:05:41) [MSC v.1929 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
使用 2.7 版執行script
>py -2.7 test.py
為不同版本的 Python 安裝套件(package)
>py -3.9 -m pip install 套件名稱
版本查看
>py --version Python 3.9.6 >py -V Python 3.9.6 >py -3 -V Python 3.9.6 >py -3.9 -V Python 3.9.6
參考:
- https://docs.python.org/3/using/windows.html#python-launcher-for-windows
3. Using Python on Windows ── Python 3.9.7 documentation - https://www.python.org/dev/peps/pep-0397/
PEP 397 -- Python launcher for Windows | Python.org - https://magicjackting.pixnet.net/blog/post/225113189
Python: Python 多版本管理 @ 傑克! 真是太神奇了! :: 痞客邦 :: - https://www.cnblogs.com/Neeo/p/8393805.html
Python - What's the Python Launcher? - 听雨危楼 - 博客园
沒有留言:
張貼留言