Python 最新版のインストール(ソースコードを使用)(Windows 上)

Windows で,Python をソースコードからビルドして,インストールする.

Python のインストール: 別ページ »で説明は,複数の方法がある.

関連する外部ページhttps://devguide.python.org/setup/#getting-the-source-code

前準備

Python 3.10,Git,CMake のインストール(Windows 上)

Pythonは,プログラミング言語の1つ. Gitは,分散型のバージョン管理システム. CMakeは,クロスプラットフォームのビルドシステム生成ツール.

手順

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)

    次のコマンドを実行

    次のコマンドは,Python ランチャーとPython 3.10とGitCMakeをインストールし,Gitパスを通すものである.

    次のコマンドでインストールされるGitは 「git for Windows」と呼ばれるものであり, Git,MinGW などから構成されている.

    winget install --scope machine Python.Launcher
    winget install --scope machine Python.Python.3.10
    winget install --scope machine Git.Git
    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\Program Files\Git\cmd\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    winget install --scope machine Kitware.CMake
    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\Program Files\CMake\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    

関連する外部ページ

サイト内の関連ページ

関連項目Python, Git バージョン管理システム, Git の利用, CMake ビルドシステム生成ツール, CMake の使用方法

Visual Studio Community 2022 のインストール(Windows 上)

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)

    次のコマンドを実行

    1. コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
    2. インストールコマンドの実行
      winget install Microsoft.VisualStudio.2022.Community --scope machine --override "--add Microsoft.VisualStudio.Workload.NativeDesktop Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core Microsoft.VisualStudio.Component.VC.CLI.Support Microsoft.VisualStudio.Component.CoreEditor Microsoft.VisualStudio.Component.NuGet Microsoft.VisualStudio.Component.Roslyn.Compiler Microsoft.VisualStudio.Component.TextTemplating Microsoft.VisualStudio.Component.Windows.SDK.Latest Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.ATL Microsoft.VisualStudio.Component.VC.ATLMFC"
      winget install Microsoft.VisualStudio.2022.Community --scope machine Microsoft.VCRedist.2015+.x64
      

      インストールされるコンポーネントの説明:

      • NativeDesktop:C++によるデスクトップアプリケーション開発のためのワークロード一式
      • NativeDesktop.Core:C++デスクトップ開発に必要な基本コンポーネント群
      • VC.CLI.Support:マネージドコードとネイティブコードの統合開発を可能にするC++/CLIサポート
      • CoreEditor:コード編集,デバッグ,検索などの基本機能を提供するVisual Studioのコアエディタ
      • NuGet:.NETライブラリの依存関係を管理するパッケージ管理システム
      • Windows.SDK.Latest:Windows 向けアプリケーション開発用SDK(Software Development Kit)
      • VC.Tools.x86.x64:32ビット及び64ビット向けC++コンパイラとビルドツール
      • VC.ATL:Windowsコンポーネント開発用のActive Template Library
      • VC.ATLMFC:デスクトップアプリケーション開発用のMicrosoft Foundation Class Library

      システム要件と注意事項:

      • 管理者権限でのインストールが必須
      • 必要ディスク容量:10GB以上
      • 推奨メモリ:8GB以上のRAM
      • インストール過程でシステムの再起動が要求される可能性がある
      • 安定したインターネット接続環境が必要

      追加のコンポーネントが必要な場合は,Visual Studio Installerを使用して個別にインストールすることが可能である.

    3. インストール完了の確認
      winget list Microsoft.VisualStudio.2022.Community
      

      トラブルシューティング:

      インストール失敗時は,以下のログファイルを確認:

      %TEMP%\dd_setup_<timestamp>.log
      %TEMP%\dd_bootstrapper_<timestamp>.log
  2. Visual Studio での C++ によるデスクトップ開発,CLI のインストール(Windows 上)
    1. Visual Studio Installer の起動

      起動方法: スタートメニューの「Visual Studio Installer」を選ぶ.

    2. Visual Studio Community 2022 で「変更」を選ぶ.
    3. C++ によるデスクトップ開発」をチェック.そして,画面右側の「インストール」の詳細で「v143 ビルドツール用 C++/CLI サポート(最新)」をチェックする.その後,「インストール」をクリック.

Python のビルドとインストール

  1. Visual Studio の x64 Native Tools コマンドプロンプトを起動.

    起動は,Windows のメニューで「Visual Studio 20..」の下の「x64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)」を選ぶ.「x64」は,64ビット版の意味である.

    「x64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)」がないとき:

    C++ ビルドツール (Build Tools) のインストールを行うことで, 「x64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)」がインストールされる.その手順は,別ページ »で説明

  2. 作業ディレクトリとインストールディレクトリを削除する
    mkdir c:\tools
    rmdir /s /q cpython
    
  3. Python のソースコードをダウンロード
    cd c:\
    git clone https://github.com/python/cpython.git
    
  4. インストール手順の説明は PCbuild\readme.txt に記載されている.一読しておく
  5. プロジェクトの再ターゲットの操作

    c:\cpython\PCbuild\pythoncore.vcxproj を開く(右クリックメニューが便利).すると Visual Studio が起動する.

    ソリューションを右クリック.右クリックメニューで「ソリューションの再ターゲット」を選ぶ.

  6. PCbuild\build.bat の実行

    * このとき作業ディレクトリ内に bzip, sqlite3, xz, zlib, libffi, openssl-bin, tcltk が自動でダウンロードが始まる

    cd c:\
    cd cpython
    .\PCbuild\build.bat
    
  7. 終了の確認
  8. 試しに起動してみる
    c:\cpython\PCbuild\amd64\python.exe
    

    exit()」で終わる

  9. pip をインストール

    pip を使うときは,「c:\cpython\PCbuild\win32\python.exe -m pip」のように使う

    curl -O https://bootstrap.pypa.io/get-pip.py
    c:\cpython\PCbuild\amd64\python.exe get-pip.py