Problem importing gurobipy on Linux64

2,873 views
Skip to first unread message

fabien

unread,
May 10, 2017, 11:46:11 AM5/10/17
to Gurobi Optimization
Hello,

I used to have Gurobi 6.5.2 installed on my computer (running on Ubuntu 14.04 LTS), and I recently installed the latest version of Gurobi (7.0.2) to replace it.

I followed the instructions found in the "Gurobi Optimizer Quick Start Guide" during the installation process. Especially:
 - I changed the lines in the .bashrc file so that they point to the new directory corresponding to Gurobi 7.0.2
 - I successfully saved the license key with the command grbgetkey.
 - I entered the command gurobi.sh in the terminal and it works.
I then followed the instructions found on the Gurobi website to install gurobipy with the setup.py file.

When I try the import gurobipy command in Python (2.7.6), I get the following error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/.local/lib/python2.7/site-packages/gurobipy/__init__.py", line 1, in <module>
    from .gurobipy import *
ImportError: libgurobi65.so: cannot open shared object file: No such file or directory

I don't understand this situation for the following reasons:
 - When Gurobi 6.5.2 was installed I could import gurobipy with Python.
 - I recently installed Gurobi 7.0.2 on a Mac computer (first Gurobi installation on this computer) and gurobipy works on this system.
 - From the error message displayed in Python, it is looking for the libgurobi65.so that is not in the directory. Indeed, libgurobi70.so is now in the ~/lib diretory and it should be the one Python opens when importing gurobipy.
 - When I enter the gurobi.sh command in the terminal, I have the following message:

Python 2.7.8 (default, Oct 28 2014, 12:34:31) 
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Gurobi Interactive Shell (linux64), Version 7.0.2
Copyright (c) 2017, Gurobi Optimization, Inc.
Type "help()" for help

gurobi> 

The version of Python displayed in this message does not seem to match with the one (2.7.6) used when I use Python in the shell.

Can you please help me with that?

Thank you,

Fabien

fabien

unread,
May 11, 2017, 9:38:56 AM5/11/17
to Gurobi Optimization
I solved the problem. I had to get rid off all the previous gurobipy installations (including the one in ~/.local/lib/python2.7/site-packages/) before running setup.py.

Rahul Bohare

unread,
Nov 6, 2017, 4:12:22 PM11/6/17
to Gurobi Optimization
Hello Fabien, I am having the same problem with gurobi75.so :
Traceback (most recent call last):
 
File "<stdin>", line 1, in <module>

 
File "/usr/local/lib/python2.7/dist-packages/gurobipy/__init__.py", line 1, in <module>
   
from .gurobipy import *
ImportError: libgurobi75.so: cannot open shared object file: No such file or directory

This is my installation of gurobipy, so I do not have any previous gurobipy installations. Can you please help me as to how to install gurobipy successfully? I am working on Ubuntu16.04.
Thanks a lot.

Daniel Espinoza

unread,
Nov 7, 2017, 6:40:59 AM11/7/17
to Gurobi Optimization
Hi Rahul,

It seems from your output that the dynamic library is not in your LD_LIBRARY_PATH environment library. If you use bash, you can add it by appending this line to your ~/.bashrc

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/gurobi751/linux64 

or wherever you installed the library.
Then type 

source ~/.bashrc, or open a new terminal and check that the path is loaded by issuing

echo $LD_LIBRARY_PATH

After that, it should work

Best,
Daniel

Rahul Bohare

unread,
Nov 7, 2017, 3:02:28 PM11/7/17
to Gurobi Optimization
Hey Daniel, thank you so much for your reply. It worked. :-)

Daniel Espinoza

unread,
Nov 8, 2017, 6:54:47 AM11/8/17
to Gurobi Optimization
Glad to hear that ;-)

pope little

unread,
Nov 29, 2018, 8:13:06 PM11/29/18
to Gurobi Optimization
Made a post earlier about how it didn't recognize trying to import Gurobi in python.
Changed the LD_LIBRARY_PATH=/Library/gurobi810/mac64/lib

Now error in Python3 interpreter comes out to be

Screen Shot 2018-11-29 at 4.55.22 PM.png

Any ideas?

pope little

unread,
Nov 30, 2018, 12:29:18 AM11/30/18
to Gurobi Optimization
This is on macOS Mojave btw

Daniel Espinoza

unread,
Dec 3, 2018, 12:32:10 PM12/3/18
to Gurobi Optimization
Hi,

That sounds like you are using the wrong version of the library with your python interpreter... did you follow the instructions in the quick start guide?

Swaprava Nath

unread,
Dec 31, 2018, 3:21:58 AM12/31/18
to Gurobi Optimization
I'm observing this error in 8.1 after my recent install. I tried the method below. It didn't work. I tried the suggestion given in the documentation: http://www.gurobi.com/documentation/8.1/quickstart_linux.pdf under "Building and running the example" -- but make mip1_c++ throws the following errors:

g++ -m64 -g -o mip1_c++ ../c++/mip1_c++.cpp -I../../include/ -L../../lib -lgurobi_c++ -lgurobi81 -lm
/tmp/ccbEODMY.o: In function `main':
/home/swaprava/Downloads/gurobi8.1.0_linux64/gurobi810/linux64/examples/build/../c++/mip1_c++.cpp:25: undefined reference to `GRBModel::addVar(double, double, double, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/swaprava/Downloads/gurobi8.1.0_linux64/gurobi810/linux64/examples/build/../c++/mip1_c++.cpp:26: undefined reference to `GRBModel::addVar(double, double, double, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/swaprava/Downloads/gurobi8.1.0_linux64/gurobi810/linux64/examples/build/../c++/mip1_c++.cpp:27: undefined reference to `GRBModel::addVar(double, double, double, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/swaprava/Downloads/gurobi8.1.0_linux64/gurobi810/linux64/examples/build/../c++/mip1_c++.cpp:35: undefined reference to `GRBModel::addConstr(GRBTempConstr const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/swaprava/Downloads/gurobi8.1.0_linux64/gurobi810/linux64/examples/build/../c++/mip1_c++.cpp:39: undefined reference to `GRBModel::addConstr(GRBTempConstr const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/swaprava/Downloads/gurobi8.1.0_linux64/gurobi810/linux64/examples/build/../c++/mip1_c++.cpp:45: undefined reference to `GRBVar::get[abi:cxx11](GRB_StringAttr) const'
/home/swaprava/Downloads/gurobi8.1.0_linux64/gurobi810/linux64/examples/build/../c++/mip1_c++.cpp:47: undefined reference to `GRBVar::get[abi:cxx11](GRB_StringAttr) const'
/home/swaprava/Downloads/gurobi8.1.0_linux64/gurobi810/linux64/examples/build/../c++/mip1_c++.cpp:49: undefined reference to `GRBVar::get[abi:cxx11](GRB_StringAttr) const'
/home/swaprava/Downloads/gurobi8.1.0_linux64/gurobi810/linux64/examples/build/../c++/mip1_c++.cpp:56: undefined reference to `GRBException::getMessage[abi:cxx11]() const'
collect2: error: ld returned 1 exit status
Makefile:84: recipe for target 'mip1_c++' failed
make: *** [mip1_c++] Error 1

There isn't any other online support for this problem, hence I'm getting in touch through email. I have installed gurobi properly and installed the license too.

Swaprava

Swaprava Nath

unread,
Jan 2, 2019, 2:34:04 AM1/2/19
to Gurobi Optimization
Any help to get my Gurobi running will be highly appreciated. 

Michael Winkler

unread,
Jan 2, 2019, 8:36:57 AM1/2/19
to Gurobi Optimization
HI Swaprava,

I believe you should have opened a different thread for this because it is not connected to this item. The issue is that the C++ compiler depending on there version switch to different ABIs. For that reason we should two different C++ libraries. In your Gurobi installation in the "lib" subdirectory you can find libgurobi_g++4.2.a and libgurobi_g++5.2.a and a softlink libgurobi_c++.a that points to the former. You can change this softlink to point to libgurobi_g++5.2.a and then rerun the make command for mip1_c++. If this still does not work we should the C++ interface code which you can build. For this follow the instructions in the "src/README" file in the Gurobi installation directory.

Best,
Michael
Reply all
Reply to author
Forward
0 new messages