Error after long time using the app [AttributeError: module 'numpy' has no attribute 'long']

Hello everyone!

I would like to ask you about an issue I have recently discovered in my Streamlit-shared app. I uploaded the app in May '21 and has been serviceable ever since to the best of my knowledge. It once faced an issue in October '21 that was quickly solved (thanks again for that!):
Error after long time using the app [AttributeError: <module ‘numba.core.serialize’]

The error was about fixing the version of the numba library. I guess an error of similar nature has been raised now (ultimately linked to its numpy dependency).

The app link:
https://malonsol-tfm-kschool-frontendflight-delay-predictor-f1hy07.streamlit.app/

When I look at the log, the following is prompted:

> 2023-05-26 17:20:12.899 Uncaught app exception
> 
> Traceback (most recent call last):
> 
>   File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/script_runner.py", line 337, in _run_script
> 
>     exec(code, module.__dict__)
> 
>   File "/app/tfm_kschool/frontend/flight_delay_predictor.py", line 64, in <module>
> 
>     import shap
> 
>   File "/home/appuser/venv/lib/python3.8/site-packages/shap/__init__.py", line 12, in <module>
> 
>     from ._explanation import Explanation, Cohorts
> 
>   File "/home/appuser/venv/lib/python3.8/site-packages/shap/_explanation.py", line 12, in <module>
> 
>     from .utils._general import OpChain
> 
>   File "/home/appuser/venv/lib/python3.8/site-packages/shap/utils/__init__.py", line 1, in <module>
> 
>     from ._clustering import hclust_ordering, partition_tree, partition_tree_shuffle, delta_minimization_order, hclust
> 
>   File "/home/appuser/venv/lib/python3.8/site-packages/shap/utils/_clustering.py", line 4, in <module>
> 
>     from numba import jit
> 
>   File "/home/appuser/venv/lib/python3.8/site-packages/numba/__init__.py", line 16, in <module>
> 
>     from numba.core import types, errors
> 
>   File "/home/appuser/venv/lib/python3.8/site-packages/numba/core/types/__init__.py", line 108, in <module>
> 
>     long_ = _make_signed(np.long)
> 
>   File "/home/appuser/venv/lib/python3.8/site-packages/numpy/__init__.py", line 320, in __getattr__
> 
>     raise AttributeError("module {!r} has no attribute "
> 
> AttributeError: module 'numpy' has no attribute 'long'

Please, could anybody shed some light to the topic? It would be very much appreciated! :slight_smile:

Best wishes,
Mario

Looks like a problem with the versions of numpy and numba you are working with because np.long was deprecated some time ago (NumPy 1.20.0 Release Notes — NumPy v2.0.dev0 Manual).

I guess your can check which combination of numpy/numba is actually compatible. From the numba release notes (Releases · numba/numba · GitHub), numba==0.57.0 and numpy==1.24 should be fine.

Hello! Thank you for your quick reply. Unfortunately it didn’t do the trick… It must have triggered new dependency incompatibilities. Now the error when I reboot the app is as follows:

2023-05-26 19:16:22.209 Uncaught app exception
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/script_runner.py", line 337, in _run_script
    exec(code, module.__dict__)
  File "/app/tfm_kschool/frontend/flight_delay_predictor.py", line 651, in <module>
    pipe = load_model(path=root + "XGBoost_pipeline_model.joblib.dat")
  File "/app/tfm_kschool/frontend/flight_delay_predictor.py", line 168, in load_model
    model = joblib.load(path)
  File "/home/appuser/venv/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 585, in load
    obj = _unpickle(fobj, filename, mmap_mode)
  File "/home/appuser/venv/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 504, in _unpickle
    obj = unpickler.load()
  File "/usr/local/lib/python3.8/pickle.py", line 1212, in load
    dispatch[key[0]](self)
  File "/usr/local/lib/python3.8/pickle.py", line 1537, in load_stack_global
    self.append(self.find_class(module, name))
  File "/usr/local/lib/python3.8/pickle.py", line 1579, in find_class
    __import__(module, level=0)
ModuleNotFoundError: No module named 'pandas.core.indexes.numeric'

What I have changed is:

  • numba==0.51.0 → 0.57.0
  • numpy==1.20.2 → 1.24.0

I’m not very familiar with the dependencies topic… but I would just love to use the same versions it used first, when everything worked fine :cry: is there any way for me to know which ones they were so as to force them?

Thanks again for your time.

Best wishes,
Mario

Looks like the incompatibility issue is with the latest version of pandas which is quite recent. Try setting that requirement to pandas<2.0.0. Not sure how to pinpoint which versions you originally had, but I would not recommend sticking with versions that are too outdated.

Thanks again for the advice. But my pandas version is indeed below 2.0.0:

numba==0.57.0
seaborn==0.11.0
xgboost==1.3.3
altair==4.1.0
matplotlib==3.3.2
streamlit==0.80.0
shap==0.39.0
missingno==0.4.2
category_encoders==2.2.2
pandas==1.1.3
numpy==1.24.0
joblib==0.17.0
scikit_learn==0.24.1

Regards,
Mario

I retrieved the original requirements.txt file, and used it as is:

seaborn==0.11.0
xgboost==1.3.3
numpy==1.19.2
altair==4.1.0
matplotlib==3.3.2
streamlit==0.80.0
shap==0.39.0
missingno==0.4.2
category_encoders==2.2.2
pandas==1.1.3
joblib==0.17.0
scikit_learn==0.24.1

Note that there is no explicit mention to the numba package.
However, it triggers another error:

[08:45:42] 📦 Processed dependencies!

2023-05-27 08:45:43.650 An update to the [server] config option section was detected. To have these changes be reflected, please restart streamlit.

2023-05-27 08:45:44.066 Generating new fontManager, this may take some time...

2023-05-27 08:45:45.272 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/script_runner.py", line 337, in _run_script

    exec(code, module.__dict__)

  File "/app/tfm_kschool/frontend/flight_delay_predictor.py", line 64, in <module>

    import shap

  File "/home/appuser/venv/lib/python3.8/site-packages/shap/__init__.py", line 12, in <module>

    from ._explanation import Explanation, Cohorts

  File "/home/appuser/venv/lib/python3.8/site-packages/shap/_explanation.py", line 12, in <module>

    from .utils._general import OpChain

  File "/home/appuser/venv/lib/python3.8/site-packages/shap/utils/__init__.py", line 1, in <module>

    from ._clustering import hclust_ordering, partition_tree, partition_tree_shuffle, delta_minimization_order, hclust

  File "/home/appuser/venv/lib/python3.8/site-packages/shap/utils/_clustering.py", line 4, in <module>

    from numba import jit

  File "/home/appuser/venv/lib/python3.8/site-packages/numba/__init__.py", line 42, in <module>

    from numba.np.ufunc import (vectorize, guvectorize, threading_layer,

  File "/home/appuser/venv/lib/python3.8/site-packages/numba/np/ufunc/__init__.py", line 3, in <module>

    from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize

  File "/home/appuser/venv/lib/python3.8/site-packages/numba/np/ufunc/decorators.py", line 3, in <module>

    from numba.np.ufunc import _internal

SystemError: initialization of _internal failed without raising an exception

I think it must be linked to numba being imported as a dependency of shap. At this point, I would need to know which version of numba was imported when shap was first called. My guess is that the numba version that was imported as a dependecy back then is not the same one that it automatically imports now, since this numba version is not explicit. Any ideas, please?

Regards,
Mario

Dear Mario,
Did you solve the above question? I encountered the same problem when using streamlit. “SystemError: initialization of _internal failed without raising an exception”.
Thanks a lot!
I am looking forward for your early reply!

Best wishes!
Star

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