ImportError No module named MySQLdb

15 篇文章 1 订阅
5 篇文章 0 订阅

ImportError No module named MySQLdb

执行命令行:pip install MySQLdb 报错

[root@10.10.131.39]# pip install MySQLdb
Collecting MySQLdb
Could not find a version that satisfies the requirement MySQLdb (from versions: )
No matching distribution found for MySQLdb
You are using pip version 8.1.2, however version 22.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

解决方案:执行pip升级,pip install --upgrade pip

再次执行命令行:pip install MySQLdb 报错

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting MySQL-python
Using cached MySQL-python-1.2.5.zip (108 kB)
ERROR: Command errored out with exit status 1:
command: /bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-LNSi1l/mysql-python/setup.py'"'"'; file='"'"'/tmp/pip-install-LNSi1l/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-3rksS0
cwd: /tmp/pip-install-LNSi1l/mysql-python/
Complete output (10 lines):
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-LNSi1l/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
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

思考:看到上述报障是缺少MySQLdb 依赖包
解决方案:python2.x依赖包为,python-devel mysql-devel

执行命令行:yum -y install python-devel mysql-devel

Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
centos-sclo-rh: mirrors.bfsu.edu.cn
centos-sclo-sclo: mirrors.tuna.tsinghua.edu.cn
epel: mirror.01link.hk
Resolving Dependencies
--> Running transaction check
---> Package mariadb-devel.x86_64 1:5.5.68-1.el7 will be installed
---> Package python-devel.x86_64 0:2.7.5-90.el7 will be updated
---> Package python-devel.x86_64 0:2.7.5-92.el7_9 will be an update
--> Processing Dependency: python(x86-64) = 2.7.5-92.el7_9 for package: python-devel-2.7.5-92.el7_9.x86_64
--> Running transaction check
---> Package python.x86_64 0:2.7.5-90.el7 will be updated
---> Package python.x86_64 0:2.7.5-92.el7_9 will be an update
--> Processing Dependency: python-libs(x86-64) = 2.7.5-92.el7_9 for package: python-2.7.5-92.el7_9.x86_64
--> Running transaction check
---> Package python-libs.x86_64 0:2.7.5-90.el7 will be updated
---> Package python-libs.x86_64 0:2.7.5-92.el7_9 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================================
Package                              Arch                          Version                                 Repository                      Size
Installing:
mariadb-devel                        x86_64                        1:5.5.68-1.el7                          base                           757 k
Updating:
python-devel                         x86_64                        2.7.5-92.el7_9                          updates                        399 k
Updating for dependencies:
python                               x86_64                        2.7.5-92.el7_9                          updates                         96 k
python-libs                          x86_64                        2.7.5-92.el7_9                          updates                        5.6 M
Transaction Summary
Install  1 Package
Upgrade  1 Package (+2 Dependent packages)
Total download size: 6.9 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/4): python-devel-2.7.5-92.el7_9.x86_64.rpm                                                                             | 399 kB  00:00:00
(2/4): python-2.7.5-92.el7_9.x86_64.rpm                                                                                   |  96 kB  00:00:00
(3/4): mariadb-devel-5.5.68-1.el7.x86_64.rpm                                                                              | 757 kB  00:00:01
(4/4): python-libs-2.7.5-92.el7_9.x86_64.rpm                                                                              | 5.6 MB  00:00:03
Total                                                                                                            1.8 MB/s | 6.9 MB  00:00:03
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating   : python-libs-2.7.5-92.el7_9.x86_64                                                                                             1/7
Updating   : python-2.7.5-92.el7_9.x86_64                                                                                                  2/7
Updating   : python-devel-2.7.5-92.el7_9.x86_64                                                                                            3/7
Installing : 1:mariadb-devel-5.5.68-1.el7.x86_64                                                                                           4/7
Cleanup    : python-devel-2.7.5-90.el7.x86_64                                                                                              5/7
Cleanup    : python-2.7.5-90.el7.x86_64                                                                                                    6/7
Cleanup    : python-libs-2.7.5-90.el7.x86_64                                                                                               7/7
Verifying  : 1:mariadb-devel-5.5.68-1.el7.x86_64                                                                                           1/7
Verifying  : python-libs-2.7.5-92.el7_9.x86_64                                                                                             2/7
Verifying  : python-2.7.5-92.el7_9.x86_64                                                                                                  3/7
Verifying  : python-devel-2.7.5-92.el7_9.x86_64                                                                                            4/7
Verifying  : python-libs-2.7.5-90.el7.x86_64                                                                                               5/7
Verifying  : python-devel-2.7.5-90.el7.x86_64                                                                                              6/7
Verifying  : python-2.7.5-90.el7.x86_64                                                                                                    7/7
Installed:
mariadb-devel.x86_64 1:5.5.68-1.el7
Updated:
python-devel.x86_64 0:2.7.5-92.el7_9
Dependency Updated:
python.x86_64 0:2.7.5-92.el7_9                                       python-libs.x86_64 0:2.7.5-92.el7_9
Complete!

完成后重新执行命令行:pip install MySQLdb 成功

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting MySQL-python==1.2.5
Using cached MySQL-python-1.2.5.zip (108 kB)
Building wheels for collected packages: MySQL-python
Building wheel for MySQL-python (setup.py) ... done
Created wheel for MySQL-python: filename=MySQL_python-1.2.5-cp27-cp27mu-linux_x86_64.whl size=84387 sha256=cd70b37d5cbd497c636cf33f200f10b929082cf4b47d8a2e5035533af6979ef5
Stored in directory: /root/.cache/pip/wheels/55/eb/3b/661bdcd5ca5a576f0331400468db9d5dcbda118fb6c85fd3ee
Successfully built MySQL-python
Installing collected packages: MySQL-python
Successfully installed MySQL-python-1.2.5
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值