0

I installed streamlit in VScode, and tried to run this.

import streamlit as st
st.title("Hello")

But I dont get streamlit to pop up in a new browser, instead I get this message in the terminal. Is this something to do with my files?

Warning: to view this Streamlit app on a browser, run it with the following command:

streamlit run c:\Users\MyName\Documents\VS code\test.py [ARGUMENTS] 
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153

7 Answers7

2

I've face the same issue. Then, solve it by following methods:

  1. First you install properly streamlit package with pip install streamlit then, go to terminal and run this

    python -m streamlit run your_script.py

1

Following the suggestion, just execute the streamlit run c:\Users\MyName\Documents\VS code\test.py in the terminal directly.

Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13
  • I tried that. I got this error message afterwards streamlit : The term 'streamlit' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + streamlit run test.py + ~~~~~~~~~ + CategoryInfo : ObjectNotFound: (streamlit:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException – applesbanana_code Apr 19 '22 at 03:45
  • @applesbanana_code This message indicates you have not installed the `streamlit` module in the environment which you are running. But when you run the python file, it prompts you to execute `streamlit run xxx`, which means you have installed the `streamlit` module. So it's a little weird. `streamlit` should exist in the `{python environment path}\Scripts` folder, you can through `get-command streamlit` in the powershell to get it. – Steven-MSFT Apr 19 '22 at 04:24
  • You can try to restart VSCode or take Ctrl+Shift+` shortcut to create a new terminal that activates the corresponding python interpreter. – Steven-MSFT Apr 19 '22 at 04:25
1

There is a way to run Streamlit code in VSCode. This enables utilizing the debugging features of VSCode.

Update the launch.json file with the following:


{
    "configurations": [
        

        {
            "name": "Python:Streamlit",
            "type": "python",
            "request": "launch",
            "module": "streamlit",
            
            "args": [
                
                "run",
                "${file}"
            ]
        }
     ]
}


Make sure the VSCode is configured with the right python environment.

YScharf
  • 1,638
  • 15
  • 20
0

You probably aren't running VS Code from the Anaconda Navigator where streamlit is downloaded. Simply open VS Code from the Anaconda Navigator and it'll work or run conda activate base on terminal before running streamlit run app.py

0

If you'd like to use vscode, you can refer to the documentation, How to use Streamlit with VS Code.

If you directly run streamlit application in vscode without the above settings, vscode thought you want to run the commandpython yourfile.py, however, your expectation command is streamlit run yourfile.py. This is why the warning message you got.

Heefan
  • 385
  • 2
  • 8
0

Here's a sample snippet of how to run a streamlit.py file. To get started, I'd suggest creating a virtual environment via conda (using virtual environments for python projects are a huge help):

conda create --name streamlit_env python=3.9
conda activate streamlit_env

Once an environment is created and activated, make sure to install streamlit.

pip install streamlit

Finally, change directory to your streamlit app and enter in the streamlit run function!

cd path_to_streamlit_directory
streamlit run your_streamlit_file.py
Doracahl
  • 336
  • 2
  • 14
-1
python -m streamlit run app.py