How to resolve ImportError in Gurobi?

2019-06-28 03:50发布

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?

标签: python gurobi
2条回答
Deceive 欺骗
2楼-- · 2019-06-28 04:04

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 ;)

查看更多
小情绪 Triste *
3楼-- · 2019-06-28 04:24

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.

查看更多
登录 后发表回答