Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve ImportError in Gurobi?

Tags:

python

gurobi

I am trying to run this example given in gurobi's example model. I am using python 3.5 with gurobi 7.0.2. When I run the code, I get the following error.

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from gurobipy import *
  File "/if5/wua4nw/anaconda3/lib/python3.5/site-packages/gurobipy/__init__.py", line 1, in <module>
    from .gurobipy import *
ImportError: libgurobi70.so: cannot open shared object file: No such file or directory

I have Gurobi installed at /if5/wua4nw/gurobi702 and I can see the required file libgurobi70.so at /if5/wua4nw/gurobi702/linux64/lib/libgurobi70.so. I am using Anaconda3 by the way.

I have seen this discussion but couldn't solve the problem yet. Can anyone shed some light so that I can solve the problem?

like image 529
Wasi Ahmad Avatar asked Mar 14 '17 23:03

Wasi Ahmad


2 Answers

I didn't notice the instructions in the official docs. Thanks to @sascha.

Users of the bash shell should add the following lines to their .bashrc files:

export GUROBI_HOME="/opt/gurobi702/linux64" 
export PATH="${PATH}:${GUROBI_HOME}/bin" 
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib" 

I followed the instructions and it solved my problem.

like image 136
Wasi Ahmad Avatar answered Oct 31 '22 20:10

Wasi Ahmad


This problem [from .gurobipy import] is caused from the IDE Pycharm on Ubuntu. I am not sure if you may face it with the other IDEs . First You can make sure from the shell the python has gurobipy installed. after you installed from the file Gurobi ~\gurobi752\win64.

python setup.py install 

And add the libraries to the paths from the shell gedit ~/.bashrc. Then just run python from the shell as normal python command python yourFileName.py and gurobi will works perfectly

In windows 10 i added the path of gurobi to the IDE pycharm after python setup.py install and pip tool for gurobipy https://sites.google.com/site/pydatalog/python/pip-for-windows, then i added the path Settings->Project Interpreter-> show all -> interpreter paths -> add your gurobi path

I hope it works cheers ;)

like image 38
xpress Avatar answered Oct 31 '22 21:10

xpress