我试图从终端运行python脚本,但收到下一条错误消息:
ImportError: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
如果我运行print sys.version,我得到:
>>> import sys
>>> print sys.version
2.7.3 (default, Feb 26 2013, 16:27:39)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]
如果我运行ldd / usr / local / bin / python
>> ldd /usr/local/bin/python
linux-vdso.so.1 => (0x00007fff219ff000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003300c00000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003300800000)
libutil.so.1 => /lib64/libutil.so.1 (0x0000003310e00000)
libm.so.6 => /lib64/libm.so.6 (0x0000003300000000)
libc.so.6 => /lib64/libc.so.6 (0x0000003300400000)
/lib64/ld-linux-x86-64.so.2 (0x00000032ffc00000)
我不明白我有哪条蟒蛇?为什么从终端运行这个python脚本失败? 我试图运行
export LD_LIBRARY_PATH=/usr/local/lib/python2.7/
没有运气......
BTW - 我已经设法使用python插件在eclipse中调试这个脚本,当我看到调试配置时,我看到PYTHONPATH设置为:
/..../eclipse/plugins/org.python.pydev_3.1.0.201312121632/pysrc/pydev_sitecustomize:/..../workspace/style_checker/src:/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg:/usr/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg:/usr/local/lib/python2.7:/usr/local/lib/python2.7/plat-linux2:/usr/local/lib/python2.7/lib-tk:/usr/local/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/site-packages
所以eclipse以某种方式管理这个python2.7库...所以我怎么能用eclipse和命令行来做呢?我究竟做错了什么 ?使用CentOS6。
答案 0 :(得分:38)
尝试查找文件libpython2.7.so.1.0
:
locate libpython2.7.so.1.0
就我而言,它显示了put:
/opt/rh/python27/root/usr/lib64/libpython2.7.so.1.0
然后将行/opt/rh/python27/root/usr/lib64
粘贴到文件/etc/ld.so.conf
并运行ldconfig
。
它解决了我的问题。古德勒克!
答案 1 :(得分:4)
也许你可以在https://stackoverflow.com/a/1100297/3559967尝试答案。
该问题的作者还指出LD_LIBRARY_PATH方法对他不起作用,但是将库路径添加到/etc/ld.so.conf
并运行ldconfig
。
答案 2 :(得分:4)
出于某种原因,这两个对我来说非常有效:
// define variables
const width = 20; // this will be > 2100
const height = 20; // this will be > 1600
const size = 20;
let elements = {};
// create all cells
for (let x = 0; x < width; x++) {
for (let y = 0; y < height; y++) {
let id = x + y * height;
let div = document.createElement("div");
div.style.border = "solid 1px black";
div.style.width = size + "px";
div.style.height = size + "px";
div.style.position = "absolute";
div.style.left = x * size + "px";
div.style.top = y * size + "px";
div.style.backgroundColor = "#F0F0F0";
let textDiv = document.createElement("div");
textDiv.innerHTML = id;
textDiv.style.position = "absolute";
textDiv.style.fontSize = "6pt";
textDiv.style.top = "1px";
textDiv.style.right = "1px";
div.appendChild(textDiv);
document.body.appendChild(div);
elements[id] = div;
}
}
function getElementOrder(width, height) {
/* BAD SLOW CODE START - This sould be better: */
const length = width * height;
const order = [0, length -1];
const result = [0, length -1];
while (order.length !== length) {
let index = 0;
let diff = 0;
for (let i = 0, m = order.length - 1; i < m; i++) {
let localDiff = order[i+1] - order[i];
if (localDiff > diff) {
index = i;
diff = localDiff;
}
}
let offset = Math.floor(diff/2);
let value = order[index] + offset;
order.splice(index + 1, 0, value);
result.push(value);
}
return result;
/* BAD SLOW CODE END */
}
// get the draw order
let order = getElementOrder(width, height);
// change color of each pixel in draw order
let interval = setInterval(() => {
if (order.length === 0) {
clearInterval(interval);
return;
}
const value = order.shift();
elements[value].style.backgroundColor = "#00abab";
}, 10);
答案 3 :(得分:1)
在64位Linux上执行32位gdb二进制文件时,我遇到了类似的问题:
arm-eabi-gdb: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
我通过安装libpython2.7:i386
(注意:i386后缀)解决了它
答案 4 :(得分:0)
这不是我热衷的主题,但我的理解是针对shared library directories should be specified at the compile step的Linux机器,尤其是Linux机器(您正在编译python二进制文件)。
例如,在链接的示例之后,这是我确保在其他库中除 外还包含libpython2.7.so.1.0
的方法:
./configure --enable-shared \
--prefix=/directory/for/Python-2.7.15 \
LDFLAGS="-Wl,--rpath=/usr/local/lib -Wl,--rpath=/directory/for/Python-2.7.15"
注意,我还将通过--prefix
选项将python安装到所选的固定目录中。对于您来说,这可能不是必需的,但是我这样做是为了为通常情况下您的python安装可能位于任何地方的提供解决方案。
使用上述解决方案,我不必导出LD_LIBRARY_PATH
或与ldconfig
混在一起
答案 5 :(得分:0)
我通过使用“ export LD_LIBRARY_PATH =“ $ {WORK_PATH} / venv / lib”解决了该问题。
答案 6 :(得分:0)
添加到正确答案:
有关如何进行以下操作的多个问题: 然后将/ opt / rh / python27 / root / usr / lib64行粘贴到文件/etc/ld.so.conf
执行此操作的正确方法是在/etc/ld.so.conf.d/中添加一个新文件,然后在该文件中添加上面的行。