Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Module Error on Linux

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"
like image 472
skr Avatar asked May 12 '14 20:05

skr


People also ask

Where can I find Python modules in Linux?

For most Linux environments, Python is installed under /usr/local , and the libraries can be found there. For Mac OS, the home directory is under /Library/Frameworks/Python.

Why am I getting a module not found error?

The 'module not found' error is a syntax error that appears when the static import statement cannot find the file at the declared path. This common syntax error is caused by letter-casing inconsistencies that are present in your filename(s) between your repository and local machine, or both.

Why do I need __ init __ py?

The __init__.py files are required to make Python treat directories containing the file as packages. This prevents directories with a common name, such as string , unintentionally hiding valid modules that occur later on the module search path.


2 Answers

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.

like image 170
Padraic Cunningham Avatar answered Oct 23 '22 07:10

Padraic Cunningham


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.

like image 44
Ian Stapleton Cordasco Avatar answered Oct 23 '22 07:10

Ian Stapleton Cordasco