Embeddable Pythonでお試し開発環境を整える

ちょっと Python を試したいけど Windows の環境汚したくないなあ、と思って Embeddable Python で環境整えた時のメモ。個人的な備忘なので抜け漏れとか端折りがありますがご容赦を。
Python は軽量な embeddable package が公式でリリースされているので、これをベースに環境を作ります。
Python 3.10.2
の Windows embeddable package (64-bit)
をダウンロードし、zipを展開して任意のフォルダに展開すればOK。
Python コンソールは通常版と終了のさせ方が違うので注意。地味にここで嵌ってしまった……
F:\workspace\python>python.exe
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
>>> print("hello")
hello
>>> import os; os._exit(1)
F:\workspace\python>
次に、パッケージ管理ツールである pip を導入します。 python310._pth
を編集して #import site
のコメントアウトを解除。
python310.zip
.
# Uncomment to run site.main() automatically
import site
https://bootstrap.pypa.io/get-pip.py をダウンロードして python を展開したのと同じフォルダに配置します。
F:\workspace\python>python get-pip.py
Collecting pip
Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
|████████████████████████████████| 1.7 MB 3.3 MB/s
Collecting setuptools
Downloading setuptools-60.5.0-py3-none-any.whl (958 kB)
|████████████████████████████████| 958 kB 3.3 MB/s
Collecting wheel
Downloading wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel, setuptools, pip
WARNING: The script wheel.exe is installed in 'F:\workspace\python\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts pip.exe, pip3.10.exe and pip3.exe are installed in 'F:\workspace\python\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-21.3.1 setuptools-60.5.0 wheel-0.37.1
F:\workspace\python>
確認。
F:\workspace\python>python -m pip --version
pip 21.3.1 from F:\workspace\python\lib\site-packages\pip (python 3.10)
F:\workspace\python>
問題なさそう。
今回は VSCode から使う想定とします。MS 純正の Python 拡張を入れたら最低限はOK。コマンドパレットから Python:Select Interpreter
を選択して python.exe
の場所を設定してあげると VSCode 上から実行可能になります。
今回はとある Python のライブラリをちょっと試してみたかっただけなので Embeddable Python で十分と判断しましたが、学習用途とかだと通常版セットアップするほうが無難ですね。Embeddable Python は通常版といろいろ違うそうですし。
参考URL
おススメ