Getting error about no pygame module (ModuleNotFoundError: No module named 'pygame')

I’m continuing to get this error, even though i have a requirements.txt file in my repository, with the following data:

pygame==2.5.0
pyaudio==0.2.13
pydub==0.25.1
speechrecognition==3.10.0
google-cloud-texttospeech==2.14.1
openai==0.27.8

my understanding is that I don’t need to call that file anywhere, and that streamlit is supposed to read it automatically.

Hi @Stanley85510, and welcome to our forums!

Just to check, do you have a similar issue when installing a prior version, e.g., pygame==2.4.0?

Thanks,
Charly

Please share a link to your public github repo.

1 Like

i have not tried this before, but I just changed both the toml file and requirements files to 2.4 and no change. I should mention that I’m not a developer, and this is the first i’m trying my hand at coding and deploying something, so it’s very possible that i’m missing something basic (i’ve only been trying to learn code for 2 weeks)

because this is for my company, i cannot share the code, but here are the contents of the rquirements file:

pygame==2.4.0

pyaudio==0.2.13

pydub==0.25.1

speechrecognition==3.10.0

google-cloud-texttospeech==2.14.1

openai==0.27.8

let me know if there is anythign else i can share

Then i cannot help either, because we are poking around in the dark.
It is probably a very trivial error, e.g. a typo of the file name or the file is in the wrong location.

Hi @Franky1 , i just created a simplified version of the code, and added it to a public repository, for review. Please take a look if you can: GitHub - Stanley85510/streamlit-test

i’m still getting this error:

2023-07-28 02:04:42.354 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/streamlit-test/streamlit_app.py", line 5, in <module>
    import audioplayer
  File "/mount/src/streamlit-test/audioplayer.py", line 1, in <module>
    import pygame
ModuleNotFoundError: No module named 'pygame'

when executing streamlit_app.py

Where is the Streamlit app running? On Streamlit Cloud or locally? It looks like the app is running locally? If so, then of course the additional python libraries need to be installed locally first, nothing magically happens in the background.


And one more note, if you plan to run your streamlit app in a hosted environment at some point, that probably won’t work then either, since pygame and other libraries you use access the local hardware directly, that won’t work then.

I’m running it in a hosted environment. I created the app through streamlit, connected it to my repo, and running stramlit_app.py.

Sounds like the issue is that some of the modules in my requirements.txt file are not compatible with running on web. Thank you for diagnosing.

Do you know how I can access local hardware (like microphone) when deploying an app on streamlit cloud?