2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【win11 + VScode 環境構築】streamlit で何か作りたいと思ったときに見る

Last updated at Posted at 2025-11-30

前提となる環境

  • OS: Windows 11 Pro
  • Python: 3.12.9(venv)
  • pip: 24.3.1
  • ターミナル: cmd

手順

Documents配下にファイルを作る前提
(C:配下に置くと権限周りで良く詰まるのでドキュメントにしてる)

1. 作業用フォルダを作る

mkdir C:\Users\ユーザー名\Documents\2025advents
cd C:\Users\ユーザー名\Documents\2025advents
code .

code .でVSCodeが起動する

2. 仮想環境(.venv)の作成と有効化

python -m venv .venv
.venv\Scripts\activate

cmd上のプロンプトの最初に(.venv)があればOK
C:直下だと管理者権限ありでcmd/vscodeを開く必要がある

3. Streamlit をインストール

仮想環境が有効になった状態で、Streamlit をインストール

pip install --upgrade pip
pip install streamlit

4. 適当に streamlit アプリを作る

pythonのコードでフロントエンドを再現する書き方をする。
一旦疎通確認として、簡単なstreamlitアプリを作成

# sample.py
import streamlit as st

st.title("アプリのタイトル")
st.write("ここに本文とか書くよ")

5. アプリを起動

cmd上で起動する。

streamlit run app.py

上手くいくとこんな表記がでる

You can now view your Streamlit app in your browser.

Local URL: http://localhost:8501

ブラウザでhttp://localhost:8501にアクセスすると
先ほど作ったstreamlitアプリが表示される

image.png

VScode画面右上にあるアプリケーション実行ボタンを押すとエラーが表示される。
あるある。

missing ScriptRunContext! This warning can be ignored when running in bare mode.
Warning: to view this Streamlit app on a browser, run it with the following command:

    streamlit run sample.py

6. 開発を進める

変更を保存をすると画面に反映できる
image.png
ファイルが変更されるとRerunが表示されるのでクリックすると、最新の変更が反映される。
Always rerunを押すと自動で反映されるようになる。

まとめ

実行は常にstreamlit run sample.py

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?