Could not build wheels for wxPython

I’m trying to deploy a private app.
During the installation, I run into an error concerning wxWidgets:

  Error running configure

  ERROR: failed building wxWidgets

  Traceback (most recent call last):

    File "/tmp/pip-install-ig48f7xp/wxpython_faa4d49c4d7d4e738e7d91ad625e24c5/build.py", line 1563, in cmd_build_wx

      wxbuild.main(wxDir(), build_options)

    File "/tmp/pip-install-ig48f7xp/wxpython_faa4d49c4d7d4e738e7d91ad625e24c5/buildtools/build_wxwidgets.py", line 379, in main

      exitIfError(wxBuilder.configure(dir=wxRootDir, options=configure_opts),

    File "/tmp/pip-install-ig48f7xp/wxpython_faa4d49c4d7d4e738e7d91ad625e24c5/buildtools/build_wxwidgets.py", line 72, in exitIfError

      raise builder.BuildError(msg)

  buildtools.builder.BuildError: Error running configure

  Finished command: build_wx (0m3.319s)

  Finished command: build (0m3.319s)

  Command '"/home/adminuser/venv/bin/python" -u build.py build' failed with exit code 1.

note: This error originates from a subprocess, and is likely not a problem with pip.

ERROR: Failed building wheel for wxPython

Running setup.py clean for wxPython

Failed to build wxPython

ERROR: Could not build wheels for wxPython, which is required to install pyproject.toml-based projects

Checking if Streamlit is installed

I saw in a forul that additionally, attrdict3 might need to be installed, so I added this to my requirements.txt.

Is there some way I can overcome this issue?
My requirements are

attrdict3 #added this to try to fix the issue
streamlit===1.33.0
matplotlib==3.8.3
numpy==1.26.4
openpyxl==3.1.2
pandas==2.2.1
scipy==1.12.0
statsmodels==0.14.1
XlsxWriter==3.2.0
scikit-learn==1.4.2
plotly==5.20.0
wxPython==4.2.1

And this is the link to my app:
https://btsapppy.streamlit.app/

Thanks!
Julia

What is the purpose of using wxPython?
I have serious doubts that this approach will ever work.

I need to export multiple files by clicking on a streamlit button (opens the explorer and lets me choose the path I want the download to be saved).
It works great on my local machine?

Well, this is probably the most used sentence in this forum…
Unfortunately a lot of things work on a local machine that breaks as soon as the streamlit app runs on any hosted environment, because client and server are not the same computer anymore…

This will almost certainly not work with wxpython.
Use st.download_button instead.


If you need more help, please share a link to your public github repo, otherwise we are poking around in the dark.

Hi Franky1, thank you for taking the time to answer.
Could you please specify why it “will almost certainly not work with wxpython”?
I use st.download_button in combination with wxpython.

I can provide the code that is using wxpython, but again, the code works fine when I use it locally, so I’d like to understand what is causing wxpython to fail while deploying (not while using!).

Here is the codesnipped that I use for it (example for 2 different files, but output files will vary so I cannot work with multiple st.download_buttons):

      summary_download = st.button("Download all results")
        if summary_download:
            app = wx.App() 
            dialog = wx.DirDialog(None, "Select a folder:", style = wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
            if dialog.ShowModal() == wx.ID_OK:
                folder_path = dialog.GetPath()  
                with st.spinner("Exporting the results, please wait"):
                    filename_a = "a.xlsx"
                    filename_b = "b.xlsx"

                    # a
                    writer = pd.ExcelWriter(folder_path + "\\" + filename_a, engine="xlsxwriter")
                    for name, df in dict_a.items():
                        df.to_excel(writer, sheet_name=name)
                    writer.close()
                   
                    # b
                    writer = pd.ExcelWriter(folder_path + "\\" + filename_b, engine="xlsxwriter")
                    for name, df in dict_b.items():
                        df.to_excel(writer, sheet_name=name)
                    writer.close()
        
            del app

Thanks
Julia

Because you have to understand how streamlit works and where the application actually runs. Think for a few seconds, where does your streamlit app run? You cannot use any GUI framework like wxpython, pyqt etc. together with streamlit. Every interaction between the streamlit app and the user must be done through the browser. Any attempt to bypass the browser is doomed to failure.

What will happen here? A new GUI instance will be started? But on which computer? Your streamlit app runs on a server and the GUI would be started on the server, but this is the wrong computer, there is neither a display nor a display-driver. Even if the app does not crash, it is the wrong device.

It is just a lucky coincidence, that your streamlit app works locally, because client and server are the same.

Deployment fails on streamlit cloud, because a lot of binary dependencies are missing, the Prerequisites are mentioned here:
https://github.com/wxWidgets/Phoenix?tab=readme-ov-file#prerequisites
On pypi there are no linux wheels provided, therefore wxpython must be build from the sources. You can fix the deployment issues, this should be possible, but you will waste a LOT of time running into a deadend

Yeah, but this is the actual problem, your approach will not work, even after fixing the deployment issues…

No, you are using st.button

This will also not work, because it will write to the filesystem of the server, not the client.

Thanks for the exhaustive answer. I did not come across any hints which modules can be used, and which cannot be used, before deploying my first app. It would be great if there were examples listed how to do this. Not everyone is an expert in how deploying apps works, that’s what this forum is hopefully for: to get help :slight_smile:

It would also be great if there were examples shown (or you could give an actual example) on how to download multiple files with the st.download_button. In my app, I use the st.download_button (well, true, not here because that does not work for multiple data files, but for another data file). I searched for hours for a solution to work on my machine, the only ways I found was inserting a download link which failed, and the solution with wxpython. As mentioned in the earlier post, I cannot use multiple download buttons as I have a variable number of files to be produced, so I’m depending on downloading them all in one go.

EDIT:

That’s the only way I can create an excel file with multiple sheets, which I abolutely need in my case!

Streamlit is a browser-based framework. If you build something to bypass the browser, it won’t work. This may not be explicitly stated in the documentation, but you should have a certain basic understanding of how things work if you want to program applications…

This is not possible with one click. And i don’t know if there is any (3rd party) streamlit component, that can do this. And I don’t know whether this is even possible, whether this functionality is generally supported by webbrowsers at all.


There are two options:

  1. Use multiple st.download_button (or steps) to download them one by one.
  2. Zip them and download this zip file by one st.download_button click.

If you have a lot of files to download, i would go for the second approach.