Windowsでの開発関係の技術日誌

Windows11でPythonを使う

PythonをWindowsにインストールする。

Pythonとは


Pythonは1991年にGuido van Rossumによって開発されたプログラミング言語である。
シンプルで読みやすい文法、豊富なライブラリ、多様な用途での利用可能性から、
現在最も人気のあるプログラミング言語の一つとなっている。

主な特徴:

– インデントによるブロック構造
– 動的型付け
– オブジェクト指向プログラミングのサポート
– 豊富な標準ライブラリ
– 機械学習やデータサイエンスでの広い採用

Pythonのインストール


WindowsへのPythonのインストールはwingetを使用して簡単に行える。
PowerShellかコマンドプロンプトを開いて以下のコマンドを実行する。

まず、利用可能なPythonパッケージを検索する:

C:\> winget search python

以下のように表示される。

<<省略>>
Python Launcher Python.Launcher 3.13.5 Command: python winget
Python 2 Python.Python.2 2.7.18150 Command: python winget
Python 3.0 Python.Python.3.0 3.0.1 Command: python winget
Python 3.1 Python.Python.3.1 3.1.4 Command: python winget
Python 3.10 Python.Python.3.10 3.10.11 Command: python winget
Python 3.11 Python.Python.3.11 3.11.9 Command: python winget
Python 3.12 Python.Python.3.12 3.12.10 Command: python winget
Python 3.13 Python.Python.3.13 3.13.12 Command: python winget
Python 3.14 Python.Python.3.14 3.14.3 Command: python winget
Python 3.2 Python.Python.3.2 3.2.5 Command: python winget
Python 3.3 Python.Python.3.3 3.3.5 Command: python winget
Python 3.4 Python.Python.3.4 3.4.4 Command: python winget
Python 3.5 Python.Python.3.5 3.5.4 Command: python winget
Python 3.6 Python.Python.3.6 3.6.8 Command: python winget
Python 3.7 Python.Python.3.7 3.7.9 Command: python winget
Python 3.8 Python.Python.3.8 3.8.10 Command: python winget
Python 3.9 Python.Python.3.9 3.9.13 Command: python winget
Python Install Manager Python.PythonInstallManager 26.0.240.0 Command: python winget
<<省略>>

この場合、Python.Python.3.14 が最新のようなのでそれをインストールしてみる。

C:\> winget install Python.Python.3.14

インストールが完了すれば新たに別のコマンドプロンプトかPwerShellを起動して確認してみる。

C:\> python -V
Python 3.14.3

バージョン番号が表示されれば成功。

Pythonのパッケージ管理コマンドであるpipの確認もしておく。

C:\> pip -V

同じくバージョン番号が表示されればOK。

VSCodeにPython拡張を入れる


VSCodeの左バーの拡張機能アイコンを押し、「Python」で検索をする。MicrosoftのPythonka拡張機能をインストールする。

Pythonプログラムの基本


適当なディレクトリを作ってVSCodeで開き、以下のファイルを作成する。

ファイル名:Hello.py
def main():
print("Hello Python")

if __name__ == "__main__":
main()

上のファイル名のタブにある▷のマークを押すとそのファイルが実行される。

コンソールから手動で実行するには

C:\> python Hello.py

とする。

以上。

コメントは受け付けていません。

トラックバック URL

https://tec01.nevernothing.jp/python/trackback/

挨拶

このサイトの著者:
NEVER_NOTHING(なっしんぐ)

フリーランスのITエンジニア
京都出身/東京在住