linux上执行python报系统导入错误_Linux上的Python模块错误

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"

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值