博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux 安装python MySQLdb
阅读量:6840 次
发布时间:2019-06-26

本文共 28278 字,大约阅读时间需要 94 分钟。

  hot3.png

安装步骤

在服务器安装了mysql 或者mysql-connect的前提下

1、安装setuptools

2、安装mysql-python

 

 

 

 

1、No module named setuptools

*原因

没有安装setuptools工具

*解决方案

在python官网https://pypi.python.org搜 setuptools工具,复制工具连接,然后如下操作

#wget https://pypi.python.org/packages/6b/dd/a7de8caeeffab76bacf56972b3f090c12e0ae6932245abbce706690a6436/setuptools-2#md5=a46750b6bd90a1343466bd57b0e2721a#tar -zxvf setuptools-28.3.0.tar.gz#python setup.py build#python setup.py install

 

 

 

2、mysql_config找不到

*现象

[root@4342116e3cd9 MySQL-python-1.2.5]# python setup.py  buildsh: mysql_config: command not foundTraceback (most recent call last):  File "setup.py", line 17, in 
metadata, options = get_config() File "/opt/MySQL-python-1.2.5/setup_posix.py", line 43, in get_config libs = mysql_config("libs_r") File "/opt/MySQL-python-1.2.5/setup_posix.py", line 25, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,))EnvironmentError: mysql_config not found[root@4342116e3cd9 MySQL-python-1.2.5]# cd MySQL-bash: cd: MySQL: No such file or directory[root@4342116e3cd9 MySQL-python-1.2.5]# cd MySQLdb/-bash: $'\345\207\272cd': command not found

*原因:

mysql_config 找不到,是因为在setup_posix.py文件中调用了mysql_config。而改参数的设置的值在site.cfg中

11 def compiler_flag(f):     12     return "-%s" % f     13     14 def mysql_config(what):     15     from os import popen     16     17     f = popen("%s --%s" % (mysql_config.path, what))     18     data = f.read().strip().split()     19     ret = f.close()     20     if ret:     21         if ret/256:     22             data = []     23         if ret/256 > 1:     24             raise EnvironmentError("%s not found" % (mysql_config.path,))     25     return data     26 mysql_config.path = "mysql_config"

打开 site.cfg 发现结果是linux的mysq_config 被注释掉了。所以只要将系统的mysql_config 注释去掉,并且后面的路径改成自己系统的mysql的mysql_config路径

[root@4342116e3cd9 MySQL-python-1.2.3]# cat site.cfg[options]# embedded: link against the embedded server library# threadsafe: use the threadsafe client# static: link against a static library (probably required for embedded)embedded = Falsethreadsafe = Truestatic = False# The path to mysql_config.# Only use this if mysql_config is not on your PATH, or you have some weird# setup that requires it.# mysql_config = /usr/local/bin/mysql_config# The Windows registry key for MySQL.# This has to be set for Windows builds to work.# Only change this if you have a different version.registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0

解决方案:

1、找到mysql_config

[root@4342116e3cd9 MySQL-python-1.2.3]# find / -name "mysql_config"/usr/bin/mysql_config

2、修改site.cfg 

[root@4342116e3cd9 MySQL-python-1.2.3]# cat site.cfg[options]# embedded: link against the embedded server library# threadsafe: use the threadsafe client# static: link against a static library (probably required for embedded)embedded = Falsethreadsafe = Truestatic = False# The path to mysql_config.# Only use this if mysql_config is not on your PATH, or you have some weird# setup that requires it.mysql_config = /usr/bin/mysql_config# The Windows registry key for MySQL.# This has to be set for Windows builds to work.# Only change this if you have a different version.#registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0

 

3、unable to execute gcc: No such file or directory

*现象

creating build/temp.linux-x86_64-2.7gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/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 -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1unable to execute gcc: No such file or directoryerror: command 'gcc' failed with exit status 1

 *原因

 由于gcc工具没有安装导致无法使用gcc工具编译

*解决方案:

#yum install gcc -y

 

 

4、/usr/bin/ld: cannot find -lmysqlclient_r

*现象

[root@4342116e3cd9 MySQL-python-1.2.3]# python setup.py  buildrunning buildrunning build_pycopying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdbrunning build_extbuilding '_mysql' extensiongcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/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 -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1In file included from _mysql.c:36:0:/usr/include/mysql/my_config.h:440:0: warning: "HAVE_WCSCOLL" redefined [enabled by default] #define HAVE_WCSCOLL ^In file included from /usr/include/python2.7/pyconfig.h:6:0,                 from /usr/include/python2.7/Python.h:8,                 from pymemcompat.h:10,                 from _mysql.c:29:/usr/include/python2.7/pyconfig-64.h:908:0: note: this is the location of the previous definition #define HAVE_WCSCOLL 1 ^gcc -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64 -L/usr/lib64 -lmysqlclient_r -lpthread -lm -lrt -ldl -lpython2.7 -o build/lib.linux-x86_64-2.7/_mysql.so/usr/bin/ld: cannot find -lmysqlclient_rcollect2: error: ld returned 1 exit statuserror: command 'gcc' failed with exit status 1

*原因

这个可以看出是找不到mysqlclient_r文件或函数; ^

从gcc -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64 -L/usr/lib64 可以得到gcc在/usr/lib64 路径下找mysqlclient_r,但是找不到。3.

 

*解决方案

这个错误找了很长时间,最后通过的 博客https://my.oschina.net/jk409/blog/392035

解决了,感谢 

解决方法(copy文件到/usr/lib64/路径下):

#cp /usr/lib64/mysql/libmysqlclient_r.a     /usr/lib64/

 最后再编译,安装,如下

[root@4342116e3cd9 MySQL-python-1.2.3]# python setup.py  buildrunning buildrunning build_pycopying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdbrunning build_ext[root@4342116e3cd9 MySQL-python-1.2.3]# python setup.py  installrunning installrunning bdist_eggrunning egg_infowriting MySQL_python.egg-info/PKG-INFOwriting top-level names to MySQL_python.egg-info/top_level.txtwriting dependency_links to MySQL_python.egg-info/dependency_links.txtreading manifest file 'MySQL_python.egg-info/SOURCES.txt'reading manifest template 'MANIFEST.in'warning: no files found matching 'MANIFEST'warning: no files found matching 'ChangeLog'warning: no files found matching 'GPL'writing manifest file 'MySQL_python.egg-info/SOURCES.txt'installing library code to build/bdist.linux-x86_64/eggrunning install_librunning build_pycopying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdbrunning build_extcreating build/bdist.linux-x86_64creating build/bdist.linux-x86_64/eggcreating build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/release.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdbcreating build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/ER.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/CR.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/FLAG.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/CLIENT.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/REFRESH.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/cursors.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/times.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/connections.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/converters.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/_mysql.so -> build/bdist.linux-x86_64/eggcopying build/lib.linux-x86_64-2.7/_mysql_exceptions.py -> build/bdist.linux-x86_64/eggbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/release.py to release.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/ER.py to ER.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CR.py to CR.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FLAG.py to FLAG.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CLIENT.py to CLIENT.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/REFRESH.py to REFRESH.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/cursors.py to cursors.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/times.py to times.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/connections.py to connections.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/converters.py to converters.pycbyte-compiling build/bdist.linux-x86_64/egg/_mysql_exceptions.py to _mysql_exceptions.pyccreating stub loader for _mysql.sobyte-compiling build/bdist.linux-x86_64/egg/_mysql.py to _mysql.pyccreating build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFOwriting build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txtzip_safe flag not set; analyzing archive contents...creating distcreating 'dist/MySQL_python-1.2.3-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to itremoving 'build/bdist.linux-x86_64/egg' (and everything under it)Processing MySQL_python-1.2.3-py2.7-linux-x86_64.eggCopying MySQL_python-1.2.3-py2.7-linux-x86_64.egg to /usr/lib64/python2.7/site-packagesAdding MySQL-python 1.2.3 to easy-install.pth fileInstalled /usr/lib64/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.eggProcessing dependencies for MySQL-python==1.2.3Finished processing dependencies for MySQL-python==1.2.3

 操作过程

[root@4342116e3cd9 opt]# cd MySQL-python-1.2.5[root@4342116e3cd9 MySQL-python-1.2.5]# lsGPL-2.0  INSTALL      MySQL_python.egg-info  PKG-INFO   _mysql.c              doc           pymemcompat.h  setup.py         setup_posix.py    site.cfgHISTORY  MANIFEST.in  MySQLdb                README.md  _mysql_exceptions.py  metadata.cfg  setup.cfg      setup_common.py  setup_windows.py  tests[root@4342116e3cd9 MySQL-python-1.2.5]# vim site.cfg[root@4342116e3cd9 MySQL-python-1.2.5]# python setup.py  buildrunning buildrunning build_pycreating buildcreating build/lib.linux-x86_64-2.7copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7creating build/lib.linux-x86_64-2.7/MySQLdbcopying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdbcopying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdbcopying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdbcopying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdbcopying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdbcopying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdbcreating build/lib.linux-x86_64-2.7/MySQLdb/constantscopying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constantscopying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constantscopying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constantscopying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constantscopying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constantscopying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constantscopying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constantsrunning build_extbuilding '_mysql' extensioncreating build/temp.linux-x86_64-2.7gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/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 -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1In file included from _mysql.c:44:0:/usr/include/mysql/my_config.h:440:0: warning: "HAVE_WCSCOLL" redefined [enabled by default] #define HAVE_WCSCOLL ^In file included from /usr/include/python2.7/pyconfig.h:6:0,                 from /usr/include/python2.7/Python.h:8,                 from _mysql.c:29:/usr/include/python2.7/pyconfig-64.h:908:0: note: this is the location of the previous definition #define HAVE_WCSCOLL 1 ^gcc -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64 -L/usr/lib64 -lmysqlclient_r -lpthread -lm -lrt -ldl -lpython2.7 -o build/lib.linux-x86_64-2.7/_mysql.so[root@4342116e3cd9 MySQL-python-1.2.5]# cp /usr/lib64/mysql/libmysqlclient_r.a  /usr/lib64/lmysqlclient_r[root@4342116e3cd9 MySQL-python-1.2.5]# python setup.py  buildrunning buildrunning build_pycopying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdbrunning build_ext[root@4342116e3cd9 MySQL-python-1.2.5]# python setup.py  installrunning installrunning bdist_eggrunning egg_infowriting MySQL_python.egg-info/PKG-INFOwriting top-level names to MySQL_python.egg-info/top_level.txtwriting dependency_links to MySQL_python.egg-info/dependency_links.txtreading manifest file 'MySQL_python.egg-info/SOURCES.txt'reading manifest template 'MANIFEST.in'writing manifest file 'MySQL_python.egg-info/SOURCES.txt'installing library code to build/bdist.linux-x86_64/eggrunning install_librunning build_pycopying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdbrunning build_extcreating build/bdist.linux-x86_64creating build/bdist.linux-x86_64/eggcreating build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/release.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdbcreating build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/ER.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/CR.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/FLAG.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/CLIENT.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/REFRESH.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/cursors.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/times.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/connections.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/converters.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/_mysql.so -> build/bdist.linux-x86_64/eggcopying build/lib.linux-x86_64-2.7/_mysql_exceptions.py -> build/bdist.linux-x86_64/eggbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/release.py to release.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/ER.py to ER.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CR.py to CR.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FLAG.py to FLAG.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CLIENT.py to CLIENT.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/REFRESH.py to REFRESH.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/cursors.py to cursors.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/times.py to times.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/connections.py to connections.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/converters.py to converters.pycbyte-compiling build/bdist.linux-x86_64/egg/_mysql_exceptions.py to _mysql_exceptions.pyccreating stub loader for _mysql.sobyte-compiling build/bdist.linux-x86_64/egg/_mysql.py to _mysql.pyccreating build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFOwriting build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txtzip_safe flag not set; analyzing archive contents...creating distcreating 'dist/MySQL_python-1.2.5-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to itremoving 'build/bdist.linux-x86_64/egg' (and everything under it)Processing MySQL_python-1.2.5-py2.7-linux-x86_64.eggCopying MySQL_python-1.2.5-py2.7-linux-x86_64.egg to /usr/lib64/python2.7/site-packagesRemoving MySQL-python 1.2.3 from easy-install.pth fileAdding MySQL-python 1.2.5 to easy-install.pth fileInstalled /usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.eggProcessing dependencies for MySQL-python==1.2.5Finished processing dependencies for MySQL-python==1.2.5[root@4342116e3cd9 MySQL-python-1.2.5]#

 

出现问题

>>> import  MySQLdb/usr/lib64/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib64/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.pyc, but /opt/MySQL-python-1.2.3 is being added to sys.pathTraceback (most recent call last):  File "
", line 1, in
File "MySQLdb/__init__.py", line 19, in
import _mysql File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in
File "build/bdist.linux-x86_64/egg/_mysql.py", line 6, in __bootstrap__ImportError: /root/.cache/Python-Eggs/MySQL_python-1.2.3-py2.7-linux-x86_64.egg-tmp/_mysql.so: undefined symbol: __cxa_pure_virtual

解决

[root@4342116e3cd9 build]# cd ..[root@4342116e3cd9 MySQL-python-1.2.5]# cd build/[root@4342116e3cd9 build]#  g++ -pthread -shared ./temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64 -l mysqlclient_r -lpthread -lm -lrt -ldl -o ./lib.linux-x86_64-2.7/_mysql.so-bash: g++: command not found[root@4342116e3cd9 build]# yum install -y gcc-c++.................Running transaction  Installing : libstdc++-devel-4.8.5-4.el7.x86_64                                                                                                                           1/2  Installing : gcc-c++-4.8.5-4.el7.x86_64                                                                                                                                   2/2  Verifying  : libstdc++-devel-4.8.5-4.el7.x86_64                                                                                                                           1/2  Verifying  : gcc-c++-4.8.5-4.el7.x86_64                                                                                                                                   2/2Installed:  gcc-c++.x86_64 0:4.8.5-4.el7Dependency Installed:  libstdc++-devel.x86_64 0:4.8.5-4.el7[root@4342116e3cd9 build]#  g++ -pthread -shared ./temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64 -l mysqlclient_r -lpthread -lm -lrt -ldl -o ./lib.linux-x86_64-2.7/_mysql.so[root@4342116e3cd9 build]#

再重新build,install python

[root@4342116e3cd9 build]# cd ..[root@4342116e3cd9 MySQL-python-1.2.5]# lsGPL-2.0  INSTALL      MySQL_python.egg-info  PKG-INFO   _mysql.c              build  doc           pymemcompat.h  setup.py         setup_common.pyc  setup_posix.pyc   site.cfgHISTORY  MANIFEST.in  MySQLdb                README.md  _mysql_exceptions.py  dist   metadata.cfg  setup.cfg      setup_common.py  setup_posix.py    setup_windows.py  tests[root@4342116e3cd9 MySQL-python-1.2.5]# python setup.py buildrunning buildrunning build_pycopying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdbrunning build_ext[root@4342116e3cd9 MySQL-python-1.2.5]# python setup.py installrunning installrunning bdist_eggrunning egg_infowriting MySQL_python.egg-info/PKG-INFOwriting top-level names to MySQL_python.egg-info/top_level.txtwriting dependency_links to MySQL_python.egg-info/dependency_links.txtreading manifest file 'MySQL_python.egg-info/SOURCES.txt'reading manifest template 'MANIFEST.in'writing manifest file 'MySQL_python.egg-info/SOURCES.txt'installing library code to build/bdist.linux-x86_64/eggrunning install_librunning build_pycopying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdbrunning build_extcreating build/bdist.linux-x86_64/eggcreating build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/release.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdbcreating build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/ER.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/CR.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/FLAG.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/CLIENT.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/REFRESH.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.7/MySQLdb/cursors.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/times.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/connections.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/MySQLdb/converters.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.7/_mysql.so -> build/bdist.linux-x86_64/eggcopying build/lib.linux-x86_64-2.7/_mysql_exceptions.py -> build/bdist.linux-x86_64/eggbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/release.py to release.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/ER.py to ER.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CR.py to CR.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FLAG.py to FLAG.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CLIENT.py to CLIENT.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/REFRESH.py to REFRESH.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/cursors.py to cursors.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/times.py to times.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/connections.py to connections.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/converters.py to converters.pycbyte-compiling build/bdist.linux-x86_64/egg/_mysql_exceptions.py to _mysql_exceptions.pyccreating stub loader for _mysql.sobyte-compiling build/bdist.linux-x86_64/egg/_mysql.py to _mysql.pyccreating build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFOwriting build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txtzip_safe flag not set; analyzing archive contents...creating 'dist/MySQL_python-1.2.5-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to itremoving 'build/bdist.linux-x86_64/egg' (and everything under it)Processing MySQL_python-1.2.5-py2.7-linux-x86_64.eggRemoving /usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.eggCopying MySQL_python-1.2.5-py2.7-linux-x86_64.egg to /usr/lib64/python2.7/site-packagesMySQL-python 1.2.5 is already the active version in easy-install.pthInstalled /usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.eggProcessing dependencies for MySQL-python==1.2.5Finished processing dependencies for MySQL-python==1.2.5[root@4342116e3cd9 MySQL-python-1.2.5]# pythonPython 2.7.5 (default, Sep 15 2016, 22:37:39)[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb/usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.pyc, but /opt/MySQL-python-1.2.5 is being added to sys.path>>>
>>> MySQLdb.version_info(1, 2, 5, 'final', 1)>>> dir(MySQLdb)['BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'DATETIME', 'DBAPISet', 'DataError', 'DatabaseError', 'Date', 'DateFromTicks', 'Error', 'FIELD_TYPE', 'IntegrityError', 'InterfaceError', 'InternalError', 'MySQLError', 'NULL', 'NUMBER', 'NotSupportedError', 'OperationalError', 'ProgrammingError', 'ROWID', 'STRING', 'TIME', 'TIMESTAMP', 'Time', 'TimeFromTicks', 'Timestamp', 'TimestampFromTicks', 'Warning', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__revision__', '__version__', '_mysql', 'apilevel', 'connect', 'connection', 'constants', 'debug', 'escape', 'escape_dict', 'escape_sequence', 'escape_string', 'get_client_info', 'paramstyle', 'release', 'result', 'server_end', 'server_init', 'string_literal', 'test_DBAPISet_set_equality', 'test_DBAPISet_set_equality_membership', 'test_DBAPISet_set_inequality', 'test_DBAPISet_set_inequality_membership', 'thread_safe', 'threadsafety', 'times', 'version_info']

 

转载于:https://my.oschina.net/jywm/blog/757973

你可能感兴趣的文章
学习五十二
查看>>
部署监控三剑客 Cacti 服务器监控
查看>>
ajax工作原理
查看>>
模拟磁盘被节点×××
查看>>
第四课-第二讲04_02_权限及权限管理
查看>>
Python入门小程序(一)
查看>>
Spring Batch 介绍
查看>>
高德地图入门(一)——工程配置
查看>>
NSOperation 简介和应用
查看>>
必读的Python入门书籍,你都看过吗?(内有福利)
查看>>
嵌入式arm产品相关知识及应用
查看>>
python select模块详解
查看>>
mac 系统下 php生成目录,移动保存文件问题
查看>>
Hibernate中update()和merge()的区别
查看>>
jmeter学习笔记之二——创建一个简单的压测脚本
查看>>
我的友情链接
查看>>
如何 Scale Up/Down Deployment?- 每天5分钟玩转 Docker 容器技术(126)
查看>>
关于Java的相关基础信息
查看>>
Java调用DotNet WebService为什么那么难?
查看>>
第二章 通过行为参数化传递代码
查看>>