Python3 安装 MySQL-python错误解决

目的

解决 python3 利用 pip 安装 MySQL-python 问题

参考错误信息

# /apps/svr/python3/bin/pip3 install MySQL-python
Collecting MySQL-python
  Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
    ERROR: Command errored out with exit status 1:
     command: /apps/svr/python3/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3k3ejkx2/MySQL-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3k3ejkx2/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 pip-egg-info
         cwd: /tmp/pip-install-3k3ejkx2/MySQL-python/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-3k3ejkx2/MySQL-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/tmp/pip-install-3k3ejkx2/MySQL-python/setup_posix.py", line 2, in <module>
        from ConfigParser import SafeConfigParser
    ModuleNotFoundError: No module named 'ConfigParser'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 19.2.3, however version 20.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

解决方法

先安装 configparser

# /apps/svr/python3/bin/pip3 install configparser
Collecting configparser
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/configparser/
  Downloading https://files.pythonhosted.org/packages/4b/6b/01baa293090240cf0562cc5eccb69c6f5006282127f2b846fad011305c79/configparser-5.0.0-py3-none-any.whl
Installing collected packages: configparser
Successfully installed configparser-5.0.0

因为安装 MySQL 插件时候需要文件大写,因此需要进行改名

 mv /apps/svr/python3/lib/python3.8/site-packages/configparser.py  /apps/svr/python3/lib/python3.8/site-packages/ConfigParser.py

假如遇到下面错误

# /apps/svr/python3/bin/pip3 install MySQL-python
Collecting MySQL-python
  Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
    ERROR: Command errored out with exit status 1:
     command: /apps/svr/python3/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-79k6iaoo/MySQL-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-79k6iaoo/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 pip-egg-info
         cwd: /tmp/pip-install-79k6iaoo/MySQL-python/
    Complete output (11 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/apps/svr/python3/lib/python3.8/site-packages/setuptools/__init__.py", line 20, in <module>
        from setuptools.dist import Distribution, Feature
      File "/apps/svr/python3/lib/python3.8/site-packages/setuptools/dist.py", line 35, in <module>
        from setuptools import windows_support
      File "/apps/svr/python3/lib/python3.8/site-packages/setuptools/windows_support.py", line 2, in <module>
        import ctypes
      File "/apps/svr/python3/lib/python3.8/ctypes/__init__.py", line 7, in <module>
        from _ctypes import Union, Structure, Array
    ModuleNotFoundError: No module named '_ctypes'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 19.2.3, however version 20.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

安装 RPM 后,重新编译 python 去 解决

# yum install -y libffi-devel
Loaded plugins: fastestmirror, security
Setting up Install Process
Determining fastest mirrors
centos6                                                                                                | 3.4 kB     00:00
epel6                                                                                                  | 3.4 kB     00:00
Not using downloaded repomd.xml because it is older than what we have:
  Current   : Thu Feb 20 18:12:16 2020
  Downloaded: Thu Feb 20 18:11:01 2020
updates6                                                                                               | 2.8 kB     00:00
vip6                                                                                                   | 3.6 kB     00:00
vip6/primary_db                                                                                        | 302 kB     00:00
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
--> Running transaction check
---> Package libffi-devel.x86_64 0:3.0.5-3.2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================
 Package                         Arch                      Version                           Repository                  Size
==============================================================================================================================
Installing:
 libffi-devel                    x86_64                    3.0.5-3.2.el6                     centos6                     18 k

Transaction Summary
==============================================================================================================================
Install       1 Package(s)

Total download size: 18 k
Installed size: 21 k
Downloading Packages:
libffi-devel-3.0.5-3.2.el6.x86_64.rpm                                                                  |  18 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : libffi-devel-3.0.5-3.2.el6.x86_64                                                                          1/1
  Verifying  : libffi-devel-3.0.5-3.2.el6.x86_64                                                                          1/1

Installed:
  libffi-devel.x86_64 0:3.0.5-3.2.el6

Complete!

安装 MySQL 插件

# /apps/svr/python3/bin/pip3 install MySQL-python
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
WARNING: You are using pip version 19.2.3, however version 20.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

显示所有插件

# /apps/svr/python3/bin/pip3 list
Package      Version
------------ -------
configparser 5.0.0
MySQL-python 1.2.5
pip          19.2.3
setuptools   41.2.0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Terry_Tsang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值