1

I have installed streamlit on my windows 10 with the latest version of anaconda with pip. I confirmed the installation by launching streamlit using streamlit hello. But when i want to import streamlit in vs code or idle shell, it gives this error:

Traceback (most recent call last): File "C:\Users\HP\AppData\Local\Programs\Python\Python310\website2.py", line 1, in import streamlit as st ModuleNotFoundError: No module named 'streamlit'

1
  • you might have multiple python versions installed on your machine? please make sure that streamlit is installed in the python 3.10, and if you want to use another python, you can change it within vscode the python interpreter in use Commented Jun 14, 2022 at 11:17

3 Answers 3

1

Make sure you choose the correct Python interpreter: ctrl+shift+P on vscode to open the command bar and type in "Python Select Interpreter". Search for ananconda or conda and you should have a list of available interpreters. Choose the one suitable to your needs.

Sign up to request clarification or add additional context in comments.

Comments

1

Looks like you have installed python with anaconda in a different path/ virtual environment and you already have python installed in your PC (program files). And also you have installed streamlit in the virtual env. You then you have to activate the virtual environment first by conda activate <virtial_env_name>. If you can't remember the name you gave to the vir_env while creating, you can list available vir_env names via conda.

The IDLE you are trying to import streamlit should be the idle installed along with the default python interpreter you are using. In vs code also you are using the default one. So you have to activate virtual env via the vs code terminal or vs code command pallet by hitting ctrl+shift+P and typing python select interpreter

Comments

1

Here is one approach to get started with streamlit on windows.

1. Create a folder say c:\myproject You can do this on other drives. 2. Open your powershell and cd or Change Directory to that folder 3. PS c:\myproject>python --version to see if you have python installed and what version 4. PS c:\myproject>python -m venv venv Creates venv folder for your virtual environment under c:\myproject with python installed. You only need to create this once. 5. PS c:\myproject>./venv/scripts/activate That will activate your virtual environment, always do this if not yet activated. 6. (venv) PS c:\myproject>python -m pip install -U pip to update your pip 7. (venv) PS c:\myproject>pip install streamlit That will install streamlit in the venv folder. You can now open c:\myproject with your vs code or other editor and write codes in say app.py. 8. (venv) PS c:\myproject>streamlit run app.py to run your streamlit app 

Note on (venv) that means your virtual environment is active. Only install lib/modules when venv is active. Installed modules will be found in the venv folder. Also run streamlit when venv is active.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.