Python Module Error on Linux
我在Linux Mint 16上使用python 2.7。如果我从程序启动器运行我的IDE(在Spyder和Pycharm上试过),我将面临错误(例如,从Alt F2的提示或桌面上的图标快捷方式)模块不加载,我得到以下错误
1 2 3 | 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 |
但是,如果我从命令行运行程序,模块正确加载,程序运行正常。我每个IDE只安装一个。两个实例的sys.path输出如下:
pycharm的sys.path输出从快捷方式运行:
1 | /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'] |
从命令行运行的pycharm的sys.path oyutput:
1 | /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'] |
gurobipy包位于/usr/lib/python2.7/dist-packages中
gurobi包的安装程序如下:
1)将下载解压缩到/ opt / gurobi562 / linux64
2)在.bashrc中添加以下行
1 2 3 4 5 | export GUROBI_HOME="/opt/gurobi562/linux64" export PATH="${PATH}:${GUROBI_HOME}/bin" export LD_LIBRARY_PATH="${GUROBI_HOME}/lib" |
3)在/ opt / gurobi562 / linux64运行python setup.py install这创建了/usr/local/lib/python2.7中的gurobipy文件夹
4)在.bashrc中添加以下行
1 | export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib/python2.7/dist- packages/gurobipy" |
您没有设置gurobipy的路径。
然后下载到
1 | cd to `/opt/gurobi562/linux64` and run `python setup.py install` |
将以下内容添加到
1 2 3 | export GUROBI_HOME="/opt/gurobi562/linux64" export PATH="${PATH}:${GUROBI_HOME}/bin" export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib" |
从bash类型
启动ipython shell并尝试
要设置系统范围的访问权限,请先创建
1 | sudo gedit /etc/ld.so.conf.d/gurobi_pi.conf |
然后加
1 | /opt/gurobi562/linux64/lib |
并保存文件。
然后输入
1 | sudo ldconfig |
更新整个系统的库。
您应该可以访问Pycharm中的共享库。
您会看到不同的行为,因为在从终端启动PyCharm(或其他编辑器)之前始终会加载
不必每次都使用终端的最佳选择是修改您正在使用的快捷方式(由您决定)以设置适当的环境变量。这些变量中最重要的是
1 | export LD_LIBRARY_PATH="/opt/gurobi562/linux64/lib:/usr/local/lib/python2.7/dist- packages/gurobipy" |
警告: