解决MySQLdb ImportError: libmysqlclient.so.18错误
2019/10/10/17:37:27 阅读:2006 来源:谷歌SEO算法 标签:
谷歌CEO
今天尝试使用MySQLdb数据库结果发现安装好MySQLdb我们导入数据时提示了ImportError:libmysqlclient.so.18: cannot open shared object file:No such file or directory不是一个有效的目录了,下面我就来把解决方法与各位分享一下.
安装MySQLdb后,import MySQLdb出错如下:
- [root@lizhongMySQL-python-1.2.3]#/usr/local/bin/python2.7
- Python2.7.6(default,Apr102014,15:45:39)
- [GCC4.4.720120313(RedHat4.4.7-4)]onlinux2
- Type"help","copyright","credits"or"license"formoreinformation.
- >>>importMySQLdb
- /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.py:3:UserWarning:Module_mysqlwasalreadyimportedfrom/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.pyc,but/soft/MySQL-python-1.2.3isbeingaddedtosys.path
- Traceback(mostrecentcalllast):
- File"<stdin>",line1,in<module>
- File"MySQLdb/__init__.py",line19,in<module>
- import_mysql
- File"build/bdist.linux-x86_64/egg/_mysql.py",line7,in<module>
- File"build/bdist.linux-x86_64/egg/_mysql.py",line6,in__bootstrap__
- ImportError:libmysqlclient.so.18:cannotopensharedobjectfile:Nosuchfileordirectory
根据最后提示,应该是找不着一个libmysqlclient.so.18的文件,于是到mysql安装目录里找到这个文件并且做一个软连接到/usr/lib,代码如下:
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
如果是64系统则,代码如下:
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
再次import MySQLdb就正常了,代码如下:
- [root@lizhongMySQL-python-1.2.3]#/usr/local/bin/python2.7
- Python2.7.6(default,Apr102014,15:45:39)
- [GCC4.4.720120313(RedHat4.4.7-4)]onlinux2
- Type"help","copyright","credits"or"license"formoreinformation.
- >>>importMySQLdb
- >>>//开源代码phpfensi.com
热门评论