I'm running a python script on a shared hosting server which until this morning had MySQL version 4. Now it has version 5. My python script can no longer connect to MySQL, as it can't find libmysqlclient_r.so.14:
我在共享托管服务器上运行python脚本,直到今天早上有MySQL版本4.现在它有版本5.我的python脚本不能再连接到MySQL,因为它找不到libmysqlclient_r.so.14:
$ python my_script.py
Traceback (most recent call last):
File "my_script.py", line 6, in ?
import MySQLdb
File "/home/lib/python2.4/site-packages/PIL-1.1.6-py2.4-linux-i686.egg/__init__.py", line 19, in ?
File "build/bdist.linux-i686/egg/_mysql.py", line 7, in ?
File "build/bdist.linux-i686/egg/_mysql.py", line 6, in __bootstrap__
ImportError: libmysqlclient_r.so.14: cannot open shared object file: No such file or directory
There are various other versions of libmysqlclient in /usr/lib:
/ usr / lib中有各种其他版本的libmysqlclient:
/usr/lib/libmysqlclient.so.15
/usr/lib/libmysqlclient.so.14
/usr/lib/mysql/libmysqlclient.la
/usr/lib/mysql/libmysqlclient.so
/usr/lib/mysql/libmysqlclient_r.so
/usr/lib/mysql/libmysqlclient_r.a
/usr/lib/mysql/libmysqlclient_r.la
/usr/lib/mysql/libmysqlclient.a
/usr/lib/libmysqlclient.so
/usr/lib/libmysqlclient_r.so
/usr/lib/libmysqlclient_r.so.15
/usr/lib/libmysqlclient_r.so.15.0.0
/usr/lib/libmysqlclient.so.15.0.0
So my question is this: how can I tell python (version 2.4.3) which version of libmysqlclient to use?
所以我的问题是这样的:我怎么能告诉python(版本2.4.3)使用哪个版本的libmysqlclient?
3 个解决方案
#1
You can't tell the dynamic linker which version of a library to use, because the SONAME (full name of the library + interface) is part of the binary.
您无法告诉动态链接器使用哪个版本的库,因为SONAME(库+接口的全名)是二进制文件的一部分。
In your case, you can try to upload libmysqlclient_r.so.14 to the host and set LD_LIBRARY_PATH
accordingly, so tell the dynamic linker which directories to search additionally to the system dirs when resolving shared objects.
在您的情况下,您可以尝试将libmysqlclient_r.so.14上载到主机并相应地设置LD_LIBRARY_PATH,因此告诉动态链接器在解析共享对象时还要向系统目录搜索哪些目录。
You can use ldd
to see if it LD_LIBRARY_PATH
works:
您可以使用ldd查看LD_LIBRARY_PATH是否有效:
$ ldd $path_to/_mysql.so
...
libmysqlclient_r.so.14 => $path_to_lib/libmysqlclient_r.so.14
...
Otherwise, there will be an error message about unresolved shared objects.
否则,将显示有关未解析的共享对象的错误消息。
Of course that can only be a temporary fix until you rebuild MySQLdb to use the new libraries.
当然,在重建MySQLdb以使用新库之前,这只能是临时修复。
#2
You will have to recompile python-mysql (aka MySQLdb) to get it to link to the new version of libmysqlclient.
您将不得不重新编译python-mysql(又名MySQLdb)以使其链接到新版本的libmysqlclient。
If your host originally set up the environment rather than you compiling it, you'll have to pester them.
如果您的主机最初设置环境而不是编译它,那么您将不得不纠缠它们。
/usr/lib/libmysqlclient.so.14
This looks like a remnant of the old libmysqlclient, and should be removed. The _r and .a (static) versions are gone and you don't really want a mixture of libraries still around, it will only risk confusing automake.
这看起来像是旧的libmysqlclient的残余,应该被删除。 _r和.a(静态)版本已经消失了,你真的不想要混合使用库,它只会让混乱的automake感到困惑。
Whilst you could make a symbolic link from libmysqlclient_r.so.14 to .15, that'd only work if the new version of the client happened to have the same ABI for the functions you wanted to use as the old - and that's pretty unlikely, as that's the whole point of changing the version number.
虽然你可以创建一个从libmysqlclient_r.so.14到.15的符号链接,但只有当新版本的客户端碰巧对你想要用作旧版本的函数具有相同的ABI时才会起作用 - 这种情况不太可能,因为这是改变版本号的重点。
#3
One solution is to set your PYTHONPATH
environment variable to have some local directory, and copy over (or link, I suppose) the version of the mysql lib you want.
一种解决方案是将PYTHONPATH环境变量设置为具有一些本地目录,并复制(或链接,我想)您想要的mysql库的版本。
#1
You can't tell the dynamic linker which version of a library to use, because the SONAME (full name of the library + interface) is part of the binary.
您无法告诉动态链接器使用哪个版本的库,因为SONAME(库+接口的全名)是二进制文件的一部分。
In your case, you can try to upload libmysqlclient_r.so.14 to the host and set LD_LIBRARY_PATH
accordingly, so tell the dynamic linker which directories to search additionally to the system dirs when resolving shared objects.
在您的情况下,您可以尝试将libmysqlclient_r.so.14上载到主机并相应地设置LD_LIBRARY_PATH,因此告诉动态链接器在解析共享对象时还要向系统目录搜索哪些目录。
You can use ldd
to see if it LD_LIBRARY_PATH
works:
您可以使用ldd查看LD_LIBRARY_PATH是否有效:
$ ldd $path_to/_mysql.so
...
libmysqlclient_r.so.14 => $path_to_lib/libmysqlclient_r.so.14
...
Otherwise, there will be an error message about unresolved shared objects.
否则,将显示有关未解析的共享对象的错误消息。
Of course that can only be a temporary fix until you rebuild MySQLdb to use the new libraries.
当然,在重建MySQLdb以使用新库之前,这只能是临时修复。
#2
You will have to recompile python-mysql (aka MySQLdb) to get it to link to the new version of libmysqlclient.
您将不得不重新编译python-mysql(又名MySQLdb)以使其链接到新版本的libmysqlclient。
If your host originally set up the environment rather than you compiling it, you'll have to pester them.
如果您的主机最初设置环境而不是编译它,那么您将不得不纠缠它们。
/usr/lib/libmysqlclient.so.14
This looks like a remnant of the old libmysqlclient, and should be removed. The _r and .a (static) versions are gone and you don't really want a mixture of libraries still around, it will only risk confusing automake.
这看起来像是旧的libmysqlclient的残余,应该被删除。 _r和.a(静态)版本已经消失了,你真的不想要混合使用库,它只会让混乱的automake感到困惑。
Whilst you could make a symbolic link from libmysqlclient_r.so.14 to .15, that'd only work if the new version of the client happened to have the same ABI for the functions you wanted to use as the old - and that's pretty unlikely, as that's the whole point of changing the version number.
虽然你可以创建一个从libmysqlclient_r.so.14到.15的符号链接,但只有当新版本的客户端碰巧对你想要用作旧版本的函数具有相同的ABI时才会起作用 - 这种情况不太可能,因为这是改变版本号的重点。
#3
One solution is to set your PYTHONPATH
environment variable to have some local directory, and copy over (or link, I suppose) the version of the mysql lib you want.
一种解决方案是将PYTHONPATH环境变量设置为具有一些本地目录,并复制(或链接,我想)您想要的mysql库的版本。