Tornado のインストール,公式ページのプログラム実行(Windows 上)

Windows での,Tornado のインストール手順を説明する.Tornado は Python の Web フレームワーク.

ユースケース:Python で手軽に Web サーバを使いたい場合

先人に感謝.

前準備

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

Pythonは,プログラミング言語の1つ. Gitは,分散型のバージョン管理システム.

手順

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. 次のコマンドを実行

    次のコマンドは,Python ランチャーとPython 3.10とGitをインストールし,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\")"
    

関連する外部ページ

サイト内の関連ページ

関連項目Python, Git バージョン管理システム, Git の利用

Tornado のインストール手順(Windows 上)

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. 使用する Python のバージョンの確認
    python --version
    
  3. pip と setuptools の更新
    python -m pip install -U pip setuptools
    
  4. パッケージのインストール
    python -m pip install -U tornade
    

    ソースコードからビルドしてインストールしたい場合の手順例

    mkdir c:\pytools
    cd c:\pytools
    rmdir /s /q tornado
    git clone https://github.com/tornado/tornado
    cd tornado
    python setup.py build
    python setup.py install
    
  5. Tornado のバージョン確認

    バージョン番号が表示されれば OK.下の図とは違うバージョンが表示されることがある.

公式ページのプログラムを動かしてみる

  1. Tornado がインストールできたかを確認したい. Python プログラムを実行する

    Python プログラムの実行: 別ページ »で説明

    Python のまとめ: 別ページ »にまとめ

    import tornado.ioloop
    import tornado.web
    
    class MainHandler(tornado.web.RequestHandler):
        def get(self):
            self.write("Hello, world")
    
    def make_app():
        return tornado.web.Application([
            (r"/", MainHandler),
        ])
    
    if __name__ == "__main__":
        app = make_app()
        app.listen(8888)
        tornado.ioloop.IOLoop.current().start()
    
  2. 確認のため,Webブラウザで http://localhost:8888 を開く