Using PYOMO + GLPK on Streamlit Share

Hello,
I’m not able to install pyomo on Streamlit Sharing.
Anyone has the same experience?

Hi @Tianoklein1, welcome to the Streamlit community!! :clap: :partying_face:

I’m sorry to hear you’re having trouble installing pyomo on sharing. Could you please share any error message you’re getting? That will help us to reproduce it. A screenshot would help too!

I was able to successfully install pyomo by including pyomo in my requirements.txt file. The demo/example repo can be found here GitHub - snehankekre/pyomo-test: test

Note that in their documentation, there is a section about conditional dependencies:

Extensions to Pyomo, and many of the contributions in pyomo.contrib, also have conditional dependencies on a variety of third-party Python packages including but not limited to: numpy, scipy, sympy, networkx, openpxl, pyodbc, xlrd, pandas, matplotlib, pymysql, pyro4, and pint. Pyomo extensions that require any of these packages will generate an error message for missing dependencies upon use.

If you’re using pyomo extensions that require additional dependencies, do include them in your requirements file.

Happy Streamlit’ing! :balloon:
Snehan

3 Likes

Sorry. My mistake.
I mean, GLPK is getting error to install on streamlitshare.

*> ```*
*>   Building wheel for glpk (PEP 517): finished with status 'error'*
*> ```*
*> *
*> ```*
*>   ERROR: Command errored out with exit status 1:*
*> ```*
*> *
*> ```*
*>    command: /home/appuser/venv/bin/python /home/appuser/venv/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmp3kc7jp2j*
*> ```*
*> *
*> ```*
*>        cwd: /tmp/pip-install-6kkq8czv/glpk_3fefe17034aa403dbbe46999c8950ed1*
*> ```*
*> *
*> ```*
*>   Complete output (14 lines):*
*> ```*
*> *
*> ```*
*>   running bdist_wheel*
*> ```*
*> *
*> ```*
*>   running build*
*> ```*
*> *
*> ```*
*>   running build_ext*
*> ```*
*> *
*> ```*
*>   building 'glpk' extension*
*> ```*
*> *
*> ```*
*>   creating build*
*> ```*
*> *
*> ```*
*>   creating build/temp.linux-x86_64-3.7*
*> ```*
*> *
*> ```*
*>   creating build/temp.linux-x86_64-3.7/src*
*> ```*
*> *
*> ```*
*>   gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DVERSION_NUMBER="0.4.6" -I/home/appuser/venv/include -I/usr/local/include/python3.7m -c src/glpk.c -o build/temp.linux-x86_64-3.7/src/glpk.o*
*> ```*
*> *
*> ```*
*>   In file included from src/glpk.c:21:*
*> ```*
*> *
*> ```*
*>   src/lp.h:24:10: fatal error: glpk.h: No such file or directory*
*> ```*
*> *
*> ```*
*>    #include <glpk.h>*
*> ```*
*> *
*> ```*
*>             ^~~~~~~~*
*> ```*
*> *
*> ```*
*>   compilation terminated.*
*> ```*
*> *
*> ```*
*>   error: command 'gcc' failed with exit status 1*
*> ```*
*> *
*> ```*
*>   ----------------------------------------*
*> ```*

Hi @Tianoklein1,

I was able to reproduce the GLPK error on my personal Linux computer and on Streamlit sharing. The problem seems to be that the glpk Python package requires some non-obvious apt-get dependencies. i.e glpk requires additional software to be installed on sharing.

In particular, it requires libglpk-dev and libgmp3-dev. To install both of them on Streamlit sharing, create a packages.txt file in your repo with the following entries:

libglpk-dev
libgmp3-dev

And include the following in your requirements.txt:

pyomo
glpk

Once you create the packages file and reboot your app, both pyomo and glpk will install successfully. :confetti_ball:

I’ve updated the demo repo with the required entries in the packages file: GitHub - snehankekre/pyomo-test: test

Happy Streamlit’ing! :balloon:
Snehan

Source: python - ERROR: Could not build wheels for glpk which use PEP 517 and cannot be installed directly - Stack Overflow

1 Like

Thanks a lot @snehankekre !!!
Did you have any tips to user ipopt library too?

1 Like

Hey @snehankekre,

I tried out your solution and the installation process works fine.

Unfortunately, the actual optimization does not work. It throws the following error message:

ApplicationError: No executable found for solver 'glpk'

File "/app/pyomo-test/app.py", line 20, in <module>
    solver_info = optimizer.solve(model, tee=True)
File "/home/appuser/venv/lib/python3.7/site-packages/pyomo/opt/base/solvers.py", line 512, in solve
    self.available(exception_flag=True)
File "/home/appuser/venv/lib/python3.7/site-packages/pyomo/opt/solver/shellcmd.py", line 128, in available
    raise ApplicationError(msg % self.name)

In the terminal, the error message reads:

Could not locate the 'glpsol' executable, which is required for solver 'glpk'

I created a fork of your pyomo-test repo and added some lines to execute a glpk optimization: pyomo-test (fork)

Can you tell me what seems to be the problem?

Edit/Solution: To make glpk run, I had to add these three packages to packages.txt:

libglpk-dev
libgmp3-dev
glpk-utils
1 Like

Hello,
Here an example:
Tianoklein/Decision_Optimization: Decision Optimization Samples (github.com)

1 Like