9

I am using python 2.7 on Linux Mint 16. I am facing an error, if I run my IDE (tried it on Spyder and Pycharm) from a program launcher (eg. from the prompt at Alt F2 or an icon shortcut on my desktop) the modules do not load and I get the following error

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

However, if I run the program from the command line the modules load correctly and the program runs fine. I have only one installation each of the IDEs. The sys.path output from the two instances are as follows:

sys.path output for Pycharm run from shortcut:

/home/XXXXXX/bin/pycharm-community-3.1.3/helpers/pydev', '/usr/local/lib/python2.7/dist-packages/pip-1.5.5-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/home/XXXXXX/PycharmProjects/untitled8'] 

sys.path oyutput for Pycharm run from command line:

/home/XXXXXX/bin/pycharm-community-3.1.3/helpers/pydev', '/usr/local/lib/python2.7/dist-packages/pip-1.5.5-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/home/XXXXXX/PycharmProjects/untitled8']

The package gurobipy is in /usr/lib/python2.7/dist-packages

Installation procedure followed for gurobi package:

1) Untarred the download to /opt/gurobi562/linux64

2) Added following lines to .bashrc

export GUROBI_HOME="/opt/gurobi562/linux64"

export PATH="${PATH}:${GUROBI_HOME}/bin"

export LD_LIBRARY_PATH="${GUROBI_HOME}/lib"

3) In /opt/gurobi562/linux64 ran python setup.py install this created the gurobipy folder in /usr/local/lib/python2.7

4) Added the following line to .bashrc

export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib/python2.7/dist-   packages/gurobipy"
6
  • have you added the necessary lines to your .bashrc file? May 12, 2014 at 20:21
  • Yes export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib/python2.7/dist-packages/gurobipy"
    – skr
    May 12, 2014 at 20:23
  • downloaded package and ran setup.py that was there in the download
    – skr
    May 12, 2014 at 20:33
  • where did you untar the files to? May 12, 2014 at 20:40
  • Edited answer with installation procedure followed
    – skr
    May 12, 2014 at 20:49

2 Answers 2

15
+50

You don't set the path to the gurobipy.

Download then untar to /opt.

cd to `/opt/gurobi562/linux64` and run `python setup.py install`

Add following to ~/.bashrc.

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

From bash type source ~/.bashrc

start ipython shell and try from gurobipy import *, it should work fine, the only error it will give is about not having a licence if you have not downloaded and installed one from here

To set system wide access, first create

sudo gedit /etc/ld.so.conf.d/gurobi_pi.conf

Then add

/opt/gurobi562/linux64/lib

and save the file.

Then enter

sudo ldconfig

to update the libs across the system. You should have access to the shared libs in Pycharm.

6
  • I have tried this, it works fine from the python shell with or without the path to gurobipy. The problem is when the IDE is run from a shortcut
    – skr
    May 12, 2014 at 21:07
  • it runs in pycharm when you run pycharm from bash yes? May 12, 2014 at 21:35
  • Yes, it runs when pycharm is run from bash
    – skr
    May 12, 2014 at 21:36
  • As a small comment - the folder /opt/gurobi562/linux64 may not exist for you if you download the newer version. replace the 562 with whatever version you untarred
    – Robert
    Oct 4, 2016 at 17:27
  • 1
    This is great. What kind of black magic is it? everything I add to that folder will be updated or what? Jan 11, 2017 at 23:09
1

You are seeing different behaviour because your .bashrc is always loaded before you launch PyCharm (or other editors) from the terminal. The other shortcuts know nothing of your .bashrc and they should not. It seems that this module requires some very interesting configuration.

Your best bet to not have to use the terminal every time is to modify the shortcuts you're using (which is up to you to figure out) to set the proper environment variables. The most important of these variables is the LD_LIBRARY_PATH.

export LD_LIBRARY_PATH="/opt/gurobi562/linux64/lib:/usr/local/lib/python2.7/dist-   packages/gurobipy"

Warning: the dist- packages seems odd but I've copied it out of your question. If it doesn't work, it's up to you to figure out what the right directory name is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.