当前位置: 移动技术网 > IT编程>数据库>Mysql > MySQL-Python安装问题小记

MySQL-Python安装问题小记

2017年12月12日  | 移动技术网IT编程  | 我要评论

安装完mysql-python后import加载模块提示以下错误,

复制代码 代码如下:

importerror: libmysqlclient_r.so.16: cannot open shared object file: no such file or directory

于是google之,总结一下解决方法:

(1)在mysql-ython的安装目录下找到site.cfg,将

#mysql_config = xxxxxxxxxxxxxxxx

注释符号去掉,并填上mysql_config的地址

(2)将mysql/lib下所有关于libmysqlclient的so文件软链接到/usr/lib下。

ln -s /usr/local/mysql/lib/mysql/libmysqlclient* /usr/lib
ldconfig

这样在加载

import _mysql

的时候就不会出错了

ubuntu 安装mysql-python遇到的问题

版本是python 2.6

使用easy_install 安装mysql-python

easy_install "mysql-python==1.2.3"
提示:error: setup script exited with error: command 'gcc' failed with exit status 1

需要安装 python-devel
sudo apt-get install python-dev
#apt-get install python-devel
再使用easy_install 安装就可以

如果使用python setup.py 安装,提示mysql_config找不到
environmenterror: mysql_config not found
需要安装下面2个开发包,需要注意的是apt-get里面是没有的,我使用新立德软件包管理器安装

libmysqld-dev
libmysqlclient-dev

安装完成以后需要修改mysql-python-1.2.3文件夹下面的setup_posix.py中的第26行,

mysql_config.path = "mysql_config"改为mysql_config的路径

whereis mysql_config查找路径

mysql_config.path = "/usr/bin/mysql_config"

再使用
python setup.py build
python setup.py install
就可以

ubuntu root 权限
sudo -i

安装mysql-python问题解决

今天在centos安装mysql-python,结果报错,报错信息如下:

 running command /home/yunpeng.jiangyp/sys/python/bin/python -c "import setuptools;__file__='/home/admin/jyp/build/mysql-python/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-mh5aya-record/install-record.txt
 running install
 running build
 running build_py
 copying mysqldb/release.py -> build/lib.linux-x86_64-2.7/mysqldb
 running build_ext
 building '_mysql' extension
 gcc -pthread -fno-strict-aliasing -g -o2 -dndebug -g -fwrapv -o3 -wall -wstrict-prototypes -fpic -dversion_info=(1,2,5,'final',1) -d__version__=1.2.5 -i/usr/include/mysql -i/home/yunpeng.jiangyp/sys/python/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -wp,-d_fortify_source=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -d_gnu_source -d_file_offset_bits=64 -d_largefile_source -fno-strict-aliasing -fwrapv
 _mysql.c:44:23: error: my_config.h: no such file or directory
 _mysql.c:46:19: error: mysql.h: no such file or directory
 _mysql.c:47:26: error: mysqld_error.h: no such file or directory
 _mysql.c:48:20: error: errmsg.h: no such file or directory
 _mysql.c:88: error: expected specifier-qualifier-list before ‘mysql'
 _mysql.c:102: error: expected specifier-qualifier-list before ‘mysql_res'

google找到答案(http://stackoverflow.com/questions/13044201/install-mysql-python-return-error-in-centos),需要先安装mysql-devel.x86_64,通过

sudo yum install mysql-devel.x86_64

再次安装成功

[yunpeng.jiangyp@v010105 ~]$ pip install mysql-python
downloading/unpacking mysql-python
 running setup.py egg_info for package mysql-python
 
installing collected packages: mysql-python
 running setup.py install for mysql-python
 building '_mysql' extension
 gcc -pthread -fno-strict-aliasing -g -o2 -dndebug -g -fwrapv -o3 -wall -wstrict-prototypes -fpic -dversion_info=(1,2,5,'final',1) -d__version__=1.2.5 -i/usr/include/mysql -i/home/yunpeng.jiangyp/sys/python/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -wp,-d_fortify_source=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -d_gnu_source -d_file_offset_bits=64 -d_largefile_source -fno-strict-aliasing -fwrapv
 gcc -pthread -shared build/temp.linux-x86_64-2.7/_mysql.o -l/usr/lib64/mysql -l/usr/lib64 -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -o build/lib.linux-x86_64-2.7/_mysql.so
 
successfully installed mysql-python
cleaning up...

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网