Linux 上的 Python 模块错误

标签 python linux pycharm linux-mint spyder

我在 Linux Mint 16 上使用 python 2.7。如果我从程序启动器运行我的 IDE(在 Spyder 和 Pycharm 上试过)(例如,从 Alt F2 的提示符或我的桌面)模块没有加载,我收到以下错误

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) 在/opt/gurobi562/linux64 中运行 python setup.py install 这在/usr/local/lib/python2.7 中创建了 gurobipy 文件夹

4) 将以下行添加到 .bashrc

export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib/python2.7/dist-   packages/gurobipy"

最佳答案

您没有设置 gurobipy 的路径。

下载然后解压到/opt

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

将以下内容添加到 ~/.bashrc

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

从 bash 类型 source ~/.bashrc

启动 ipython shell 并尝试 from gurobipy import *,它应该可以正常工作,如果您没有从 here 下载并安装许可证,它给出的唯一错误是没有许可证。

要设置系统范围的访问权限,首先创建

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

然后添加

/opt/gurobi562/linux64/lib

并保存文件。

然后输入

sudo ldconfig

更新整个系统的库。 您应该有权访问 Pycharm 中的共享库。

关于Linux 上的 Python 模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23617898/

相关文章:

python - 使用 Python 和 OpenCV 实现万花筒效果

Python 列表理解昂贵

python - AWS Lambda 不导入 LXML

linux - POSIX 线程中的互斥概念

python - PyCharm 4.5 中外部库的索引失败

python - Gmail API - ModuleNotFoundError : No module named 'googleapiclient' - Python 3. 7

python - 模块脚本的 Pyinstaller

xml - 比较两个xml文件

python - 仅在 PyCharm 中发生的异常

linux - 在 dd-wrt ​​路由器上使用 Optware 软件包和启动脚本