Gurobi with Django on uwsgi on Ubuntu
AnsweredI have a Django web app that uses Gurobi. I deploy my app on an Ubuntu server running uwsgi with nginx. My app has a virtual environment. So to install Gurobi, I activated the environment and cd to the Gurobi installation directory and run python setup.py install and it seemed like Gurobi was installed successfully to my virtual environment (I could run "from gurobipy import *" in the python shell). However, when I run the app using uwsgi, I get an error saying
Import error: libgurobi90.so: cannot open shared object file: No such file or directory
I thought that the environment variables (i.e. PATH, LD_LIBRARY_PATH and GUROBI_HOME) were somehow not set up correctly, but when I put a debugging print in, the environment variables seemed correctly set up.
This is the code for the debugging print before the Gurobi import statement
import os
import pprint
pprint.pprint(dict(os.environ))
from gurobipy import *
and this is what I'm getting back
{ 'DJANGO_SETTINGS_MODULE': 'app.settings',
'GUROBI_HOME': '/opt/gurobi902/linux64',
'LD_LIBRARY_PATH': '/opt/gurobi902/linux64/lib',
'PATH': '/other/paths:/opt/gurobi902/linux64/bin',
'TZ': 'Australia/Brisbane',
'UWSGI_ORIGINAL_PROC_NAME': '/path/to/venv/bin/uwsgi',
'UWSGI_RELOADS': '0'}
Traceback (most recent call last):
...
ImportError: libgurobi90.so: cannot open shared object file: No such file or directory
So I think the environment variables are already correctly setup? For people who know more about uwsgi, this is how I'm setting up the environment variables in my uwsgi configuration file
[uwsgi]
...
env = GUROBI_HOME=/opt/gurobi902/linux64
env = PATH=$(PATH):/opt/gurobi902/linux64/bin
env = LD_LIBRARY_PATH=/opt/gurobi902/linux64/lib
What might be the cause of the ImportError?
Also please feel free to reply below if you think this question is lacking information.
Thanks all.
-
Basically, wherever the Django code runs, it needs to see the shared library file libgurobi90.so. To do this with the LD_LIBRARY_PATH variable, you will need to set this as an environment variable so that Linux can access the shared library.
That said, if you have sudo privileges to this computer, it might be easier just to put the shared library into /usr/local/lib, e.g.:
sudo ln -s $GUROBI_HOME/lib/libgurobi90.so /usr/local/lib && sudo ldconfig
0
Please sign in to leave a comment.
Comments
1 comment