1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

python、bottleの導入方法、使い方

Last updated at Posted at 2023-07-09

bottleは簡単にアプリが作れるPythonのフレームワーク。

pythonとbottleの導入方法

pythonをインストールする(Windows)

①以下のサイトを開く。
https://www.python.org/
②Downloadsにカーソルを合わせ、"Download for Windows"の下のボタンをクリックする。
image.png
③インストーラを開き、画面下の"Add Python 3.10(バージョン) to PATH"に必ずチェックを入れる
④"Install Now"をクリックしてインストールを開始する。
⑤インストールが終わったら、以下のような画面が出る。
image.png
⑥インストールができているか確認する。
 コマンドプロンプトを開く。(管理者権限でなくて良い。)
 以下のコマンドを実行する。

python --version

⑦以下のように表示されたらOK。

Python 3.11.4(バージョン)

コマンドプロンプトでPythonのバージョンが出ない場合

・Pythonをインストールし直す。
(インストールする時に必ず、"Add Python 3.10(バージョン) to PATH"にチェックを入れる。)
・アプリ実行エイリアスをオフにする。
 以下のサイトを参照。
 https://www.out48.com/archives/5720/

bottleの導入方法

①コマンドプロンプトを開く。(管理者権限でなくて良い。)
②ファイルを保存する場所にフォルダを作成する。
②以下のコマンドを実行する。

cd ②のファイルパス
pip install bottle

③動作確認をする。
 ・②pythonファイルを作成する。(名前は何でもよい)
  ※必ずbottle.pyと同じ階層にファイルを作成する。
 ・pythonファイルに以下のコードを記述する。

# -*- coding:utf-8 -*-

from bottle import route, run

@route('/hello')
def hello():
    return "Hello world!"

run(host='localhost', port=8080, debug=True)

 ・以下のコマンドをコマンドプロンプトで実行する。

python 〇〇.py

 ・以下のURLにアクセスすると確認ができる。
  http://localhost:8080/hello
  ※Ctrl+Cで実行が止まる。

参考サイト

Pythonの環境構築
https://prog-8.com/docs/python-env-win

コマンドプロンプトでPythonのバージョンが表示されない場合
https://www.out48.com/archives/5720/
https://happy-tenshoku.com/post-6679/

bottleの使い方
https://qiita.com/pulat/items/d401853c2bf1f7b5661b

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?