场景:
我们在使用python 进行简单项目开发的时候或许会考虑使用cgi作为服务(因为主流WEB服务器基本都支持CGI),本次以HTTPD作为WEB服务器进行python 链接MYSQL数据库测试中遇到的问题
1、执行“pip install mysql-python”命令,我们收到了如下代码片段的错误
[root@hdfs-master cgi-bin]# pip install mysql-python
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting mysql-python
Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-YlIQYH/mysql-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-YlIQYH/mysql-python/
2、经过资料查询,我们需要执行“yum install mysql-devel”进行一些mysql的配置
[root@hdfs-master cgi-bin]# yum install mysql-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.yun-idc.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package mariadb-devel.x86_64 1:5.5.60-1.el7_5 will be installed
--> Processing Dependency: openssl-devel(x86-64) for package: 1:mariadb-devel-5.5.60-1.el7_5.x86_64
--> Running transaction check
---> Package openssl-devel.x86_64 1:1.0.2k-16.el7 will be installed
--> Processing Dependency: zlib-devel(x86-64) for package: 1:openssl-devel-1.0.2k-16.el7.x86_64
--> Processing Dependency: krb5-devel(x86-64) for package: 1:openssl-devel-1.0.2k-16.el7.x86_64
--> Running transaction check
---> Package krb5-devel.x86_64 0:1.15.1-37.el7_6 will be installed
--> Processing Dependency: libkadm5(x86-64) = 1.15.1-37.el7_6 for package: krb5-devel-1.15.1-37.el7_6.x86_64
--> Processing Dependency: krb5-libs(x86-64) = 1.15.1-37.el7_6 for package: krb5-devel-1.15.1-37.el7_6.x86_64
--> Processing Dependency: libverto-devel for package: krb5-devel-1.15.1-37.el7_6.x86_64
--> Processing Dependency: libselinux-devel for package: krb5-devel-1.15.1-37.el7_6.x86_64
--> Processing Dependency: libcom_err-devel for package: krb5-devel-1.15.1-37.el7_6.x86_64
--> Processing Dependency: keyutils-libs-devel for package: krb5-devel-1.15.1-37.el7_6.x86_64
---> Package zlib-devel.x86_64 0:1.2.7-18.el7 will be installed
--> Running transaction check
---> Package keyutils-libs-devel.x86_64 0:1.5.8-3.el7 will be installed
---> Package krb5-libs.x86_64 0:1.15.1-34.el7 will be updated
---> Package krb5-libs.x86_64 0:1.15.1-37.el7_6 will be an update
---> Package libcom_err-devel.x86_64 0:1.42.9-13.el7 will be installed
---> Package libkadm5.x86_64 0:1.15.1-37.el7_6 will be installed
---> Package libselinux-devel.x86_64 0:2.5-14.1.el7 will be installed
--> Processing Dependency: libsepol-devel(x86-64) >= 2.5-10 for package: libselinux-devel-2.5-14.1.el7.x86_64
--> Processing Dependency: pkgconfig(libsepol) for package: libselinux-devel-2.5-14.1.el7.x86_64
--> Processing Dependency: pkgconfig(libpcre) for package: libselinux-devel-2.5-14.1.el7.x86_64
---> Package libverto-devel.x86_64 0:0.2.5-4.el7 will be installed
--> Running transaction check
---> Package libsepol-devel.x86_64 0:2.5-10.el7 will be installed
---> Package pcre-devel.x86_64 0:8.32-17.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================================================================================================================================================
Package Arch Version Repository Size
=========================================================================================================================================================================================================================================
Installing:
mariadb-devel x86_64 1:5.5.60-1.el7_5 base 754 k
Installing for dependencies:
keyutils-libs-devel x86_64 1.5.8-3.el7 base 37 k
krb5-devel x86_64 1.15.1-37.el7_6 updates 271 k
libcom_err-devel x86_64 1.42.9-13.el7 base 31 k
libkadm5 x86_64 1.15.1-37.el7_6 updates 178 k
libselinux-devel x86_64 2.5-14.1.el7 base 187 k
libsepol-devel x86_64 2.5-10.el7 base 77 k
libverto-devel x86_64 0.2.5-4.el7 base 12 k
openssl-devel x86_64 1:1.0.2k-16.el7 base 1.5 M
pcre-devel x86_64 8.32-17.el7 base 480 k
zlib-devel x86_64 1.2.7-18.el7 base 50 k
Updating for dependencies:
krb5-libs x86_64 1.15.1-37.el7_6 updates 803 k
Transaction Summary
=========================================================================================================================================================================================================================================
Install 1 Package (+10 Dependent packages)
Upgrade ( 1 Dependent package)
Total download size: 4.3 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/12): keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm | 37 kB 00:00:00
(2/12): libcom_err-devel-1.42.9-13.el7.x86_64.rpm | 31 kB 00:00:00
(3/12): krb5-libs-1.15.1-37.el7_6.x86_64.rpm | 803 kB 00:00:00
(4/12): krb5-devel-1.15.1-37.el7_6.x86_64.rpm | 271 kB 00:00:00
(5/12): libkadm5-1.15.1-37.el7_6.x86_64.rpm | 178 kB 00:00:00
(6/12): libselinux-devel-2.5-14.1.el7.x86_64.rpm | 187 kB 00:00:00
(7/12): libverto-devel-0.2.5-4.el7.x86_64.rpm | 12 kB 00:00:00
(8/12): libsepol-devel-2.5-10.el7.x86_64.rpm | 77 kB 00:00:00
(9/12): mariadb-devel-5.5.60-1.el7_5.x86_64.rpm | 754 kB 00:00:00
(10/12): pcre-devel-8.32-17.el7.x86_64.rpm | 480 kB 00:00:00
(11/12): zlib-devel-1.2.7-18.el7.x86_64.rpm | 50 kB 00:00:00
(12/12): openssl-devel-1.0.2k-16.el7.x86_64.rpm | 1.5 MB 00:00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 3.5 MB/s | 4.3 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : krb5-libs-1.15.1-37.el7_6.x86_64 1/13
Installing : libkadm5-1.15.1-37.el7_6.x86_64 2/13
Installing : libcom_err-devel-1.42.9-13.el7.x86_64 3/13
Installing : libsepol-devel-2.5-10.el7.x86_64 4/13
Installing : zlib-devel-1.2.7-18.el7.x86_64 5/13
Installing : pcre-devel-8.32-17.el7.x86_64 6/13
Installing : libselinux-devel-2.5-14.1.el7.x86_64 7/13
Installing : libverto-devel-0.2.5-4.el7.x86_64 8/13
Installing : keyutils-libs-devel-1.5.8-3.el7.x86_64 9/13
Installing : krb5-devel-1.15.1-37.el7_6.x86_64 10/13
Installing : 1:openssl-devel-1.0.2k-16.el7.x86_64 11/13
Installing : 1:mariadb-devel-5.5.60-1.el7_5.x86_64 12/13
Cleanup : krb5-libs-1.15.1-34.el7.x86_64 13/13
Verifying : keyutils-libs-devel-1.5.8-3.el7.x86_64 1/13
Verifying : libverto-devel-0.2.5-4.el7.x86_64 2/13
Verifying : 1:openssl-devel-1.0.2k-16.el7.x86_64 3/13
Verifying : krb5-libs-1.15.1-37.el7_6.x86_64 4/13
Verifying : libkadm5-1.15.1-37.el7_6.x86_64 5/13
Verifying : pcre-devel-8.32-17.el7.x86_64 6/13
Verifying : libselinux-devel-2.5-14.1.el7.x86_64 7/13
Verifying : zlib-devel-1.2.7-18.el7.x86_64 8/13
Verifying : libsepol-devel-2.5-10.el7.x86_64 9/13
Verifying : libcom_err-devel-1.42.9-13.el7.x86_64 10/13
Verifying : krb5-devel-1.15.1-37.el7_6.x86_64 11/13
Verifying : 1:mariadb-devel-5.5.60-1.el7_5.x86_64 12/13
Verifying : krb5-libs-1.15.1-34.el7.x86_64 13/13
Installed:
mariadb-devel.x86_64 1:5.5.60-1.el7_5
Dependency Installed:
keyutils-libs-devel.x86_64 0:1.5.8-3.el7 krb5-devel.x86_64 0:1.15.1-37.el7_6 libcom_err-devel.x86_64 0:1.42.9-13.el7 libkadm5.x86_64 0:1.15.1-37.el7_6 libselinux-devel.x86_64 0:2.5-14.1.el7 libsepol-devel.x86_64 0:2.5-10.el7
libverto-devel.x86_64 0:0.2.5-4.el7 openssl-devel.x86_64 1:1.0.2k-16.el7 pcre-devel.x86_64 0:8.32-17.el7 zlib-devel.x86_64 0:1.2.7-18.el7
Dependency Updated:
krb5-libs.x86_64 0:1.15.1-37.el7_6
Complete!
3、再次执行pip install mysql-python 即可安装成功
[root@hdfs-master cgi-bin]# pip install mysql-python
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting mysql-python
Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
Installing collected packages: mysql-python
Running setup.py install for mysql-python ... done
Successfully installed mysql-python-1.2.5