Streamlit multipage app crashes on import pandas or import plotly.express statement

the code is more or less a copy paste of sample code given at link page_link

The way to run code will be streamlit run streamlit_app.py
NOTE: The checked in version of the code works

Now if you go to file: pages/page2.py and uncomment line # import pandas as pd and run again the code crashes on running when you click on ‘backtesting page’ on the side bar

If you’re creating a debugging post, please include the following info:

  1. Are you running your app locally or is it deployed? → locally
  2. If your app is deployed:
    a. Is it deployed on Community Cloud or another hosting platform? → N/A
    b. Share the link to the public deployed app. → /NA
  3. Share the link to your app’s public GitHub repository (including a requirements file).
    GitHub - alsm6169/streamlit-login
  4. Share the full text of the error message (not a screenshot).
    zsh: segmentation fault streamlit run stock_app_main.py
  5. Share the Streamlit and Python versions.
    % python --version
    Python 3.11.9
    % streamlit version
    Streamlit, version 1.35.0

Seems to work for me both locally and deployed to streamlit cloud. It must be specific to your local setup.

Are you sure your python environment is set to the correct one? Like if using conda?

Maybe also run this command and see what it shows:

pip freeze > requirements.txt

altair==5.3.0
attrs==23.2.0
beautifulsoup4==4.12.3
blinker==1.8.2
cachetools==5.3.3
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
frozendict==2.4.4
gitdb==4.0.11
GitPython==3.1.43
html5lib==1.1
idna==3.7
Jinja2==3.1.4
jsonschema==4.22.0
jsonschema-specifications==2023.12.1
lxml==5.2.2
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdurl==0.1.2
multitasking==0.0.11
numpy==1.26.4
packaging==24.0
pandas==2.2.2
peewee==3.17.5
pillow==10.3.0
platformdirs==4.2.2
plotly==5.22.0
protobuf==4.25.3
pyarrow==16.1.0
pydeck==0.9.1
Pygments==2.18.0
python-dateutil==2.9.0.post0
pytz==2024.1
referencing==0.35.1
requests==2.32.2
rich==13.7.1
rpds-py==0.18.1
setuptools==69.5.1
six==1.16.0
smmap==5.0.1
soupsieve==2.5
streamlit==1.35.0
tenacity==8.3.0
toml==0.10.2
toolz==0.12.1
tornado==6.4
typing_extensions==4.12.0
tzdata==2024.1
urllib3==2.2.1
webencodings==0.5.1
wheel==0.43.0
yfinance==0.2.40

on mac os →
% sw_vers
ProductName: macOS
ProductVersion: 11.7.10
BuildVersion: 20G1427

Not sure if that’s good or not but you could run this too:

 pip list --outdated

I always use conda (miniconda) to be sure my packages are always right for any given project. Are you using conda?

interesting…did not know this command
yes, I am using miniconda …
After updating also it crashes… :frowning:

hmm,…any tips? what could be wrong?

In case it helps here’s what I ended up doing to be sure my conda ENV is always correct, when I run it from my menu launcher app, because there can be issues with the envorinment depending on how you run it, but I decided for me this was the best way. If you just run the normal conda activate command it’s not guaranteed to always work.

conda_path="/home/clay/miniconda3"
export PATH="$conda_path/bin:$PATH"
source $conda_path/bin/activate quanta_agent

if [[ "$CONDA_DEFAULT_ENV" == "quanta_agent" ]]; then
  python3 quanta-agent.py
else
  echo "Failed to set Conda Environment: Expected quanta_agent but found $CONDA_DEFAULT_ENV"
  sleep 10s
  exit 1
fi

Looks like an issue in your conda environment. What if you import pandas in the main script instead (or in addition to) page2?

ok, I will try to google if there is a fix…
calling import pandas in main script, causes app to crash immediately (login screen does not even run)
i wonder if there is a compatibility issue between pandas 2.2.0 and streamlit 1.35.0 (though at this stage I am not calling any pandas method)

You could also try a test where you just run only that pandas import to see if that even works. Start with simplest possible scenario, and if it works then start adding stuff back a little at a time, to see when it stops working and that will tell you where the problem is. Also try writing to some log files and see how far along your log output can get before it stops.

Forget about streamlit, it has nothing to do with your issue. What if you just import pandas, without involving streamlit at all?

No - OP is correct. I am running into the exact same issue and I have a minimal repro. Streamlit curses my pandas install. See this pastebin where I:

  1. Install pandas in a fresh venv
  2. import pandas successfully
  3. install streamlit
  4. fail to import pandas due to segfault
  5. uninstall streamlit
  6. pandas import segfault persists.

That is a huge improvement. Unfortunately I cannot really reproduce it. I guess it is specific to the arm architecture or your python.

Since the problem persists after uninstalling streamlit, the culprit may be some of the dependencies installed along with it. I would expect pandas to work again if you uninstall all of them. If that is the case, some trial and error would tell you what package is causing the issue.

Also, if you are using the system python, you can try a different one from python.org.

Based on the hints & suggestions above, I seem to have a solution that works for me. Instead of creating conda environment I have created a pip environment i.e.

%python -m venv env   
%source env/bin/activate   
%pip install -r requirements.txt

Though I do not like this workflow (only cause I am used to conda), it seems to do the trick.
@toymodel333 let me know if this works for you too (or did I get plain lucky).

After some further debugging, I was able to confirm that that the issue came from pyarrow depednency. I downgraded to 15.0.0 and segfault went away.

3 Likes

@toymodel333 I was really struggling with this, thank you very much! This message needs more visibility ^^

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