为什么80%的码农都做不了架构师?>>>   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  build
sh: mysql_config: command not found
Traceback (most recent call last):File "setup.py", line 17, in <module>metadata, options = get_config()File "/opt/MySQL-python-1.2.5/setup_posix.py", line 43, in get_configlibs = mysql_config("libs_r")File "/opt/MySQL-python-1.2.5/setup_posix.py", line 25, in mysql_configraise 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" % f1314 def mysql_config(what):15     from os import popen1617     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 data26 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 = False
threadsafe = True
static = 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 = False
threadsafe = True
static = 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.7
gcc -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=1
unable to execute gcc: No such file or directory
error: 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  build
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 -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=1
In 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_r
collect2: error: ld returned 1 exit status
error: 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.

*解决方案

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

解决了,感谢 jk409

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

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

最后再编译,安装,如下

[root@4342116e3cd9 MySQL-python-1.2.3]# python setup.py  build
running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
running build_ext
[root@4342116e3cd9 MySQL-python-1.2.3]# python setup.py  install
running install
running bdist_egg
running egg_info
writing MySQL_python.egg-info/PKG-INFO
writing top-level names to MySQL_python.egg-info/top_level.txt
writing dependency_links to MySQL_python.egg-info/dependency_links.txt
reading 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/egg
running install_lib
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
running build_ext
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/release.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb
creating build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/ER.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/CR.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/FLAG.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/CLIENT.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/REFRESH.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/cursors.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/times.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/connections.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/converters.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/_mysql.so -> build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.7/_mysql_exceptions.py -> build/bdist.linux-x86_64/egg
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/release.py to release.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/ER.py to ER.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CR.py to CR.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FLAG.py to FLAG.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/cursors.py to cursors.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/times.py to times.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/connections.py to connections.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/converters.py to converters.pyc
byte-compiling build/bdist.linux-x86_64/egg/_mysql_exceptions.py to _mysql_exceptions.pyc
creating stub loader for _mysql.so
byte-compiling build/bdist.linux-x86_64/egg/_mysql.py to _mysql.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/MySQL_python-1.2.3-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing MySQL_python-1.2.3-py2.7-linux-x86_64.egg
Copying MySQL_python-1.2.3-py2.7-linux-x86_64.egg to /usr/lib64/python2.7/site-packages
Adding 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.egg
Processing dependencies for MySQL-python==1.2.3
Finished processing dependencies for MySQL-python==1.2.3

操作过程

[root@4342116e3cd9 opt]# cd MySQL-python-1.2.5
[root@4342116e3cd9 MySQL-python-1.2.5]# ls
GPL-2.0  INSTALL      MySQL_python.egg-info  PKG-INFO   _mysql.c              doc           pymemcompat.h  setup.py         setup_posix.py    site.cfg
HISTORY  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  build
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
creating build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-x86_64-2.7
gcc -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=1
In 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  build
running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
running build_ext
[root@4342116e3cd9 MySQL-python-1.2.5]# python setup.py  install
running install
running bdist_egg
running egg_info
writing MySQL_python.egg-info/PKG-INFO
writing top-level names to MySQL_python.egg-info/top_level.txt
writing dependency_links to MySQL_python.egg-info/dependency_links.txt
reading 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/egg
running install_lib
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
running build_ext
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/release.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb
creating build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/ER.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/CR.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/FLAG.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/CLIENT.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/REFRESH.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/cursors.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/times.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/connections.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/converters.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/_mysql.so -> build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.7/_mysql_exceptions.py -> build/bdist.linux-x86_64/egg
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/release.py to release.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/ER.py to ER.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CR.py to CR.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FLAG.py to FLAG.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/cursors.py to cursors.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/times.py to times.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/connections.py to connections.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/converters.py to converters.pyc
byte-compiling build/bdist.linux-x86_64/egg/_mysql_exceptions.py to _mysql_exceptions.pyc
creating stub loader for _mysql.so
byte-compiling build/bdist.linux-x86_64/egg/_mysql.py to _mysql.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/MySQL_python-1.2.5-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing MySQL_python-1.2.5-py2.7-linux-x86_64.egg
Copying MySQL_python-1.2.5-py2.7-linux-x86_64.egg to /usr/lib64/python2.7/site-packages
Removing MySQL-python 1.2.3 from easy-install.pth file
Adding 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.egg
Processing dependencies for MySQL-python==1.2.5
Finished 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.path
Traceback (most recent call last):File "<stdin>", line 1, in <module>File "MySQLdb/__init__.py", line 19, in <module>import _mysqlFile "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in <module>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 transactionInstalling : libstdc++-devel-4.8.5-4.el7.x86_64                                                                                                                           1/2Installing : gcc-c++-4.8.5-4.el7.x86_64                                                                                                                                   2/2Verifying  : libstdc++-devel-4.8.5-4.el7.x86_64                                                                                                                           1/2Verifying  : 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]# ls
GPL-2.0  INSTALL      MySQL_python.egg-info  PKG-INFO   _mysql.c              build  doc           pymemcompat.h  setup.py         setup_common.pyc  setup_posix.pyc   site.cfg
HISTORY  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 build
running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
running build_ext
[root@4342116e3cd9 MySQL-python-1.2.5]# python setup.py install
running install
running bdist_egg
running egg_info
writing MySQL_python.egg-info/PKG-INFO
writing top-level names to MySQL_python.egg-info/top_level.txt
writing dependency_links to MySQL_python.egg-info/dependency_links.txt
reading 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/egg
running install_lib
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
running build_ext
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/release.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb
creating build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/ER.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/CR.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/FLAG.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/CLIENT.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/REFRESH.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/cursors.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/times.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/connections.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/converters.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/_mysql.so -> build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.7/_mysql_exceptions.py -> build/bdist.linux-x86_64/egg
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/release.py to release.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/ER.py to ER.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CR.py to CR.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FLAG.py to FLAG.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/cursors.py to cursors.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/times.py to times.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/connections.py to connections.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/converters.py to converters.pyc
byte-compiling build/bdist.linux-x86_64/egg/_mysql_exceptions.py to _mysql_exceptions.pyc
creating stub loader for _mysql.so
byte-compiling build/bdist.linux-x86_64/egg/_mysql.py to _mysql.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_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 it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing MySQL_python-1.2.5-py2.7-linux-x86_64.egg
Removing /usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg
Copying MySQL_python-1.2.5-py2.7-linux-x86_64.egg to /usr/lib64/python2.7/site-packages
MySQL-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.egg
Processing dependencies for MySQL-python==1.2.5
Finished processing dependencies for MySQL-python==1.2.5
[root@4342116e3cd9 MySQL-python-1.2.5]# python
Python 2.7.5 (default, Sep 15 2016, 22:37:39)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "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

linux 安装python MySQLdb相关推荐

  1. linuxpip安装python包_Windows+Linux安装Python包管理工具pip

    Windows+Linux安装Python包管理工具pip Windows安装Python包管理工具pip pip是一个Python包管理工具,主要是用于安装PyPI上的软件包,可以替代easy_in ...

  2. linux安装版本的python,linux安装python各种版本.md

    ### linux安装python各种版本 PS:首先按照本文的问题按照教程解决,再安装编译python [python各个版本大全](https://www.python.org/ftp/pytho ...

  3. Linux 安装python 3.8(Linux 的版本为 Centos 7)

    Linux 安装python 3.8(Linux 的版本为 Centos 7) 前言:喜欢傻瓜式复制粘贴的,不会思考安装过程中报错的,不建议看这个,可以去看看其他的,看了安装不了,又喷人,自己不会,解 ...

  4. cygwin mysql安装教程_Cygwin 下安装Python MySQLdb

    Cygwin 下安装Python MySQLdb 1) cygwin 更新 运行 cygwin/setup-x86_64.exe a 输入mysql,选择下面的包安装: libmysqlclient- ...

  5. Linux 安装 Python

    文章目录 Linux安装python 一. 获取源码包 二. 安装python 三. 虚拟环境 四. 脚本文件 五. 安装conda Linux安装python 一. 获取源码包 我们访问这个网址,就 ...

  6. linux安装python虚拟环境_linux环境下安装python虚拟环境及注意事项

    创建python虚拟环境virtualenv.virtualenvwrapper 1,为什么需要搭建虚拟环境 由于当机器上两个项目依赖于相同包的不同版本时,会导致项目运行失败,此时可以安装虚拟环境 . ...

  7. linux 安装python 3.x,Linux 安装python3.x步骤

    本文转发自博客园非真的文章,内容略有改动 linux系统本身默认安装有2.x版本的python,版本x根据不同版本系统有所不同,通过python --V 或 python --version 查看系统 ...

  8. linux安装python

    以下为在 Unix & Linux 平台上安装 Python 的简单步骤: 打开 WEB 浏览器访问 https://www.python.org/downloads/source/ 选择适用 ...

  9. 嵌入式Linux安装Python环境,linux环境下安装python 3

    说明: 在linux环境下,都默认安装python 2的环境,由于python3在python2的基础上升级较大,所以安装python 3环境用于使用最新的python 3的语法. 安装过程: 1.下 ...

最新文章

  1. 数据结构与算法:11 Leetcode同步练习(四)
  2. 用Python编写代码分析《英雄联盟》游戏胜利的最重要因素
  3. python怎么读取文件-Python如何读取文件
  4. 一些数据结构的思想(3)
  5. TensorFlow for Hackers - Part III
  6. 浅析NameNode/DataNode/SecondaryNameNode源码注释
  7. php如何转类型,PHP数据类型转换
  8. Spring Data JPA 从入门到精通~SpEL表达式的支持
  9. 竖流式沉淀池集水槽设计计算_竖流式沉淀池的设计
  10. hihoCoder 1014trie树(字典树)
  11. 从实操教学到赛题演练,腾讯专家亲授TI-ONE平台操作攻略!
  12. 网上商城连接mysql_做一个网上网上购物网站,请问怎么连接数据库?
  13. 【每日一博】asynchat 异步socket命令/响应处理器
  14. vue中使用kindeditor编辑器_vue中使用kindeditor富文本编辑器
  15. 2023届计算机毕业设计源码
  16. 国内有哪些不错的计算机视觉团队?
  17. linux查看java虚拟机内存_JVM:查看java内存情况命令
  18. [sudo rm -rf /bin/] Linux误删除/bin目录恢复
  19. 分布式架构、大数据、机器学习、搜索、推荐、广告
  20. 基于Matlab Robotics Toolbox的Dobot机械臂运动规划(3)

热门文章

  1. Mybatis打印调试sql的两种方式
  2. 行代码实现数据集可视化、分析与比较
  3. js 上传头像img
  4. HDU 1022[Train Problem I] 栈的应用
  5. iOS开发工具篇:cocoaPods 添加第三方库链接报错
  6. log4j, common-logging, slf4j 关系
  7. 邮箱数据库营销的概念及其特点介绍
  8. 点击按钮取GridView当前被操作行的数据
  9. Windows:让Windows XP中的IIS支持多站点的工具
  10. ASP.NET、Ajax、Silverlight学习电子资料汇总