Tornado のインストール,公式ページのプログラム実行(Windows 上)
Windows での,Tornado のインストール手順を説明する.Tornado は Python の Web フレームワーク.
ユースケース:Python で手軽に Web サーバを使いたい場合
先人に感謝.
前準備
Python 3.10,Git のインストール(Windows 上)
Pythonは,プログラミング言語の1つ. Gitは,分散型のバージョン管理システム.
【手順】
- Windows で,コマンドプロンプトを管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
- 次のコマンドを実行
次のコマンドは,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 の公式ページ: https://www.python.org/
- Git の公式ページ: https://git-scm.com/
【サイト内の関連ページ】
【関連項目】 Python, Git バージョン管理システム, Git の利用
Tornado のインストール手順(Windows 上)
- Windows で,コマンドプロンプトを管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
- 使用する Python のバージョンの確認
python --version
- pip と setuptools の更新
python -m pip install -U pip setuptools
- パッケージのインストール
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
- Tornado のバージョン確認
バージョン番号が表示されれば OK.下の図とは違うバージョンが表示されることがある.
公式ページのプログラムを動かしてみる
- Tornado がインストールできたかを確認したい.
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()
- 確認のため,Webブラウザで http://localhost:8888 を開く