ModuleNotFoundError: No module named 'pkg_resources' when deploying

Link to the app: https://eqseismfm-bmkg-alt.streamlit.app/

Link to the Github repository: GitHub - GalihPRep/EQ_Seism_FM

Error message:

  /home/adminuser/venv/lib/python3.10/site-packages/streamlit/runtime/scriptru  

  nner/exec_code.py:129 in exec_func_with_error_handling                        

                                                                                

  /home/adminuser/venv/lib/python3.10/site-packages/streamlit/runtime/scriptru  

  nner/script_runner.py:687 in code_to_exec                                     

                                                                                

  /home/adminuser/venv/lib/python3.10/site-packages/streamlit/runtime/scriptru  

  nner/script_runner.py:166 in _mpa_v1                                          

                                                                                

  /home/adminuser/venv/lib/python3.10/site-packages/streamlit/navigation/page.  

  py:310 in run                                                                 

                                                                                

  /mount/src/eq_seism_fm/EQ_Analysis.py:9 in <module>                           

                                                                                

      6 from bs4 import BeautifulSoup                                           

      7 from PIL import Image                                                   

      8 from streamlit_folium import st_folium                                  

  ❱   9 from obspy.geodetics import locations2degrees, degrees2kilometers       

     10 import folium                                                           

     11                                                                         

     12 st.set_page_config(page_title="EQ Analysis", layout="wide", page_icon=  

                                                                                

  /home/adminuser/venv/lib/python3.10/site-packages/obspy/__init__.py:34 in     

  <module>                                                                      

                                                                                

    31 import warnings                                                          

    32                                                                          

    33 # don't change order                                                     

  ❱ 34 from obspy.core.utcdatetime import UTCDateTime  # NOQA                   

    35 from obspy.core.util import _get_version_string                          

    36 __version__ = _get_version_string(abbrev=10)                             

    37 from obspy.core.trace import Trace  # NOQA                               

                                                                                

  /home/adminuser/venv/lib/python3.10/site-packages/obspy/core/__init__.py:120  

  in <module>                                                                   

                                                                                

    117 .. _NumPy: http://www.numpy.org                                         

    118 """                                                                     

    119 # don't change order                                                    

  ❱ 120 from obspy.core.utcdatetime import UTCDateTime  # NOQA                  

    121 from obspy.core.util.attribdict import AttribDict  # NOQA               

    122 from obspy.core.trace import Stats, Trace  # NOQA                       

    123 from obspy.core.stream import Stream, read  # NOQA                      

                                                                                

  /home/adminuser/venv/lib/python3.10/site-packages/obspy/core/utcdatetime.py:  

  21 in <module>                                                                

                                                                                

      18 import warnings                                                        

      19                                                                        

      20 import numpy as np                                                     

  ❱   21 from obspy.core.util.deprecation_helpers import ObsPyDeprecationWarni  

      22                                                                        

      23                                                                        

      24 # based on https://www.myintervals.com/blog/2009/05/20/iso-8601, w/ w  

                                                                                

  /home/adminuser/venv/lib/python3.10/site-packages/obspy/core/util/__init__.p  

  y:22 in <module>                                                              

                                                                                

    19 """                                                                      

    20 # import order matters - NamedTemporaryFile must be one of the first!    

    21 from obspy.core.util.attribdict import AttribDict                        

  ❱ 22 from obspy.core.util.base import (ALL_MODULES, DEFAULT_MODULES,          

    23 │   │   │   │   │   │   │   │     NATIVE_BYTEORDER, NETWORK_MODULES,     

    24 │   │   │   │   │   │   │   │     NamedTemporaryFile, _read_from_plugin  

    25 │   │   │   │   │   │   │   │     create_empty_data_chunk, get_example_  

                                                                                

  /home/adminuser/venv/lib/python3.10/site-packages/obspy/core/util/base.py:26  

  in <module>                                                                   

                                                                                

     23 from pathlib import PurePath                                            

     24                                                                         

     25 import numpy as np                                                      

  ❱  26 import pkg_resources                                                    

     27 from pkg_resources import get_entry_info, iter_entry_points             

     28                                                                         

     29 from obspy.core.util.misc import to_int_or_zero, buffered_load_entry_p  

Streamlit version: ≥1.40.0 (as written in requirements.txt)

Python version: 3.10 (in Community Cloud).

Welcome to the Streamlit community and thanks for sharing your error details and repo! :tada: The error traceback shows that your app fails when importing ObsPy, specifically at import pkg_resources, which is not found in your environment.

This happens because pkg_resources is part of the setuptools package, but setuptools is not listed in your requirements.txt. To fix this, add setuptools to your requirements.txt file, commit, and redeploy your app. For more info, see the official Streamlit docs on dependency management and community troubleshooting examples.

Sources:

I’ve added setuptools to my requirements.txt and redeployed it but the issue still persists

UPDATE: I found out that the app installed setuptools twice during the deployment, each has different version. I fixed it by specifying the library’s version with the older one, so setuptools became setuptools==80.9.0. I don’t know though if the issue happened because of that, or if it was because of the wrong version getting installed alongside the correct one, or how it even happened in the first place.

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