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:


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?


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:







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/", line 552, in _run_script
    exec(code, module.__dict__)
  File "/mount/src/streamlit-test/", line 5, in <module>
    import audioplayer
  File "/mount/src/streamlit-test/", line 1, in <module>
    import pygame
ModuleNotFoundError: No module named 'pygame'

when executing

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

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?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.