在本文中,我们将详细介绍CentOS7使用pip安装mysql-python出错解决方案的各个方面,同时,我们也将为您带来关于centos6.5安装MySQL-python模块、centos7安装my
在本文中,我们将详细介绍CentOS7使用pip安装mysql-python出错解决方案的各个方面,同时,我们也将为您带来关于centos 6.5 安装MySQL-python模块、centos 7 安装mysql-python、Centos pip安装mysqldb提示EnvironmentError: mysql_config not found解决办法、centos 下安装 MySQL-python 库出错的有用知识。
本文目录一览:- CentOS7使用pip安装mysql-python出错解决方案
- centos 6.5 安装MySQL-python模块
- centos 7 安装mysql-python
- Centos pip安装mysqldb提示EnvironmentError: mysql_config not found解决办法
- centos 下安装 MySQL-python 库出错
CentOS7使用pip安装mysql-python出错解决方案
具体错误:
[root@localhost liuyuantao]# pip install mysql-python
Collecting mysql-python
Downloading MySQL-python-1.2.5.zip (108kB)
100% |████████████████████████████████| 112kB 77kB/s
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-build-7Pn8K6/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-build-7Pn8K6/mysql-python/
上面的错误是由于缺少mysql_config文件导致,查看下mysql_config文件是否存在
[root@localhost liuyuantao]# find / -name mysql_config
find: ‘/proc/5155’: No such file or directory
find: ‘/run/user/1000/gvfs’: Permission denied
果然mysql_config没有找到,是因为缺少mysql-devel,导致mysql_config丢失,安装mysql-devel即可。
yum install mysql-devel
若提示错误应该是MySQL的源存在问题,安装MySQL的源即可,具体见CentOS7编译安装MySQL5.7之后安装mysql-devel出错解决方案
mysql-devel安装成功之后,查看mysql_config是否存在
[root@localhost liuyuantao]# find / -name mysql_config
find: ‘/run/user/1000/gvfs’: Permission denied
/usr/bin/mysql_config
在/usr/bin/mysql_config已经存在,使用pip安装mysql-python即可
root@localhost liuyuantao]# pip install mysql-python
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Building wheels for collected packages: mysql-python
Running setup.py bdist_wheel for mysql-python ... done
Stored in directory: /root/.cache/pip/wheels/38/a3/89/ec87e092cfb38450fc91a62562055231deb0049a029054dc62
Successfully built mysql-python
Installing collected packages: mysql-python
Successfully installed mysql-python-1.2.5
接下来我们就可以使用python操作MySQL数据库了
[root@localhost liuyuantao]# python
Python 2.7.5 (default, Aug 18 2016, 15:58:25)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> 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'']
>>> MySQLdb.version_info
(1, 2, 5, ''final'', 1)
>>>
centos 6.5 安装MySQL-python模块
如果你服务器环境允许yum,安装MySQL-python模块就很简单了
[python]view plaincopy
yuminstallMysqL-python-y
当然也可以源码安装该模块
首先安装setuptools,下载源代码包:
[plain]
wgethttp://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
解压后
pythonsetup.pybuild
pythonsetup.pyinstall
然后安装一些扩展库
yum-yinstallrpm-buildgcc-c++mysql-develpython-devel
最后安装MySQL-python
下载源代码包:
wgethttp://download.sourceforge.net/sourceforge/MysqL-python/MysqL-python-1.2.3.tar.gz
解压进入安装目录。
编辑site.cfg,把MysqL_config那一行取消注释,并改为:
MysqL_config=/usr/lib64/MysqL/MysqL_config(根据自己MysqL安装位置定义)
pythonsetup.pybuild
pythonsetup.pyinstall
测试安装
[root@woyoo:/tmp/MysqL-python-1.2.3]#python
Python2.6.6(r266:84292,Feb222013,00:00:18)
[GCC4.4.720120313(RedHat4.4.7-3)]onlinux2
Type"help","copyright","credits"or"license"formoreinformation.
>>>importMysqLdb
/usr/lib64/python2.6/site-packages/MysqL_python-1.2.3-py2.6-linux-x86_64.egg/_MysqL.py:3:UserWarning:Module_MysqLwasalreadyimportedfrom/usr/lib64/python2.6/site-packages/MysqL_python-1.2.3-py2.6-linux-x86_64.egg/_MysqL.pyc,but/tmp/MysqL-python-1.2.3isbeingaddedtosys.path
>>>
报出一大堆警告信息,解决办法:删除MysqL-python源目录,再测试一下:
centos 7 安装mysql-python
1.首先要先下载,MysqLdb下载地址:
https://pypi.python.org/pypi/MysqL-python/1.2.5
2. unzip MysqL-python-1.2.5;
3. cd MysqL-python-1.2.5;
python setup.py install;
此时报错:
Traceback (most recent call last):
File "setup.py",line 17,in <module>
Metadata,options = get_config()
File "/root/MysqL-python-1.2.5/setup_posix.py",line 43,in get_config
libs = MysqL_config("libs_r")
File "/root/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
原因是没有安装MysqL-devel;
yum install MysqL-devel;
4.重新运行python setup.py install;
Centos pip安装mysqldb提示EnvironmentError: mysql_config not found解决办法
解决办法: 1.yum install MysqL-devel 2.然后 pip install MysqL-pythoncentos 下安装 MySQL-python 库出错
安装失败背景:
项目需要,在 centos 环境下写个脚本实现某些功能,需要调用 mysql 数据库相关 api,于是就通过 pip 来安装 MySQL-python 库来实现相关功能,于是乎出现了 “EnvironmentError: mysql_config not found” 错误,导致安装失败。
解决:
通过 yum install -y mysql-devel python-devel 预先安装这两包,然后再去执行: pip install MySQL-python 结果安装成功。
原因:
mysql-devel、python-devel 包中包含了 MySQL-python 库的一些依赖信息,如果未装这些包安装过程中会报某些依赖异常。
关于CentOS7使用pip安装mysql-python出错解决方案的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于centos 6.5 安装MySQL-python模块、centos 7 安装mysql-python、Centos pip安装mysqldb提示EnvironmentError: mysql_config not found解决办法、centos 下安装 MySQL-python 库出错等相关知识的信息别忘了在本站进行查找喔。
本文标签: