No module named ‘Plotly’

Hey guys, i have already added my requirements.txt but is not working

im getting this error

2023-09-10 13:13:21.352 Uncaught app exception

Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script

    exec(code, module.__dict__)

  File "/mount/src/dash_ana/streamlit_app.py", line 2, in <module>

    import plotly.express as px

ModuleNotFoundError: No module named 'plotly'

My repo is here GitHub - GiordanoSouza/Dash_ana: Data Analysis Sales Dashboard with Python and Streamlit
Streamlit_app: https://dashboardanahealth.streamlit.app/

Thanks in advance!

You’re encountering a “ModuleNotFoundError” when trying to run your Streamlit app due to a missing Plotly library. To fix this, first double-check your “requirements.txt” file for any typos or discrepancies in the library name. Ensure it’s accurately listed.

Next, consider creating a virtual environment to isolate dependencies. Activate it and run “pip install -r requirements.txt” to install all required packages.

If deploying to Streamlit Cloud, make sure you’ve followed their setup instructions and specified the correct Python version. Sometimes, simply rebooting or redeploying your app can resolve such issues. These steps should help you resolve the Plotly-related error and get your app up and running. Good luck with your data analysis dashboard project!

The names of the requirements is correct.

How can i create this virtual environment? Could you explain better?

No worries! To create a virtual environment, you can follow these steps:

  1. Open your terminal or command prompt.

  2. Navigate to your project directory using the cd command. For example, if your project is in a folder called “my_project,” you’d type: cd my_project

  3. Once you’re inside your project folder, you can create a virtual environment by running: python -m venv venv_name

    Replace venv_name with the name you want to give to your virtual environment. It’s common to use names like “env” or “venv.”

  4. After creating the virtual environment, you’ll need to activate it. On Windows, you can do this with: venv_name\Scripts\activate, and on macOS/Linux, it’s: source venv_name/bin/activate

  5. Once activated, your terminal should show the virtual environment’s name in the prompt. Now, you can install your project’s dependencies using pip install -r requirements.txt.

That’s it! Your virtual environment is set up, and you should be able to run your project without module not found errors. Remember to activate the virtual environment each time you work on your project and deactivate it when you’re done with deactivate.

I tried cloning your repo and deployed it using my account and it works flawlessly. Try changing your python version to 3.10.
Deployed app - https://dashana-temp.streamlit.app/

He is trying to deploy from streamlit cloud which automatically assigns a virtual env for deploying. I think he has some issues in setting up the deployment from the streamlit app dashboard. But still one should always use virtual envs for local development.

Thanks!

Is there any command to use in the Terminal so i can change the python version?

Or i have to uninstall and download it again?

Thanks!

Are you trying to deploy to streamlit cloud, if yes - then simply go to ‘Advanced Settings’ while deploying the app and select python version 3.10

:pray: You are a god, thanks a lot. It worked.

I am no god!
Glad it worked for you.