Python PIP Mysql-python 报错 ERROR: Command errored out with exit status 1: python setup.py egg_info C

pip install mysql-python

安装Mysql-python时,报错,先看下错误内容:


    ERROR: Command errored out with exit status 1:
     command: /root/training/Python-3.7.0/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-wbf036ga/mysql-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-wbf036ga/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-ntpyg1z0
         cwd: /tmp/pip-install-wbf036ga/mysql-python/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "", line 1, in <module>
      File "/tmp/pip-install-wbf036ga/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/tmp/pip-install-wbf036ga/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.

根据以往的经验是不能无脑用最后一句去搜

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

从这里开始看

    Complete output (7 lines):
    Traceback (most recent call last):
      File "", line 1, in <module>
      # setup.py,导出setup_posix报错
      File "/tmp/pip-install-wbf036ga/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      # setup_posix.py,导出ConfigParser包报错
      File "/tmp/pip-install-wbf036ga/mysql-python/setup_posix.py", line 2, in <module>
        from ConfigParser import SafeConfigParser
      # 最终错误原因是没有ConfigParser这个库
    ModuleNotFoundError: No module named 'ConfigParser'

错误原因是没有ConfigParser这个库,我们去Lib里看下,是有一个小写的configParser.py没有ConfigParser.pyPython PIP Mysql-python 报错 ERROR: Command errored out with exit status 1: python setup.py egg_info C_第1张图片
第一种办法,我先把小写的改为大写的,

cp configparser.py /usr/local/Python-3.7.0/Lib/ConfigParser.py

Python PIP Mysql-python 报错 ERROR: Command errored out with exit status 1: python setup.py egg_info C_第2张图片

    ERROR: Command errored out with exit status 1:
     command: /root/training/Python-3.7.0/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-wbf036ga/mysql-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-wbf036ga/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-ntpyg1z0
         cwd: /tmp/pip-install-wbf036ga/mysql-python/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "", line 1, in <module>
      File "/tmp/pip-install-wbf036ga/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/tmp/pip-install-wbf036ga/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.

第二种办法,修改setup_posix.py,找了几个没找到,费神

# 没有找到
find -name setup_posix.py
# setup.py
find -name setup.py

下面几个都翻了,没找到

./root/training/Python-3.7.0/lib/python3.7/site-packages/twisted/internet/iocpreactor/setup.py
./root/training/Python-3.7.0/lib/python3.7/test/libregrtest/setup.py
./usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/setup.py
./usr/local/Python-3.7.0/Doc/includes/setup.py
./usr/local/Python-3.7.0/Tools/test2to3/setup.py
./usr/local/Python-3.7.0/setup.py
./usr/local/Python-3.7.0/Lib/test/libregrtest/setup.py

最后自己下了去官网下了一个安装包,上传上去解压后,找到了setup_posix.py

https://pypi.org/project/MySQL-python/#files
参考:https://www.cnblogs.com/lxt287994374/p/3910509.html

 # 你自己的Mysql安装路径
 export LD_LIBRARY_PATH=/usr/bin
 # https://www.cnblogs.com/lxt287994374/p/3910509.html

 # 注意你自己的路径
 sudo ln -s /usr/lib/mysql/libmysqlclient.so /usr/lib/libmysqlclient.so.14
 
 # 这个很重要,否则后面会报错ImportError: libmysqlclient.so.14: cannot open shared object  file
 sudo ldconfig
 
 # 安装报错,熟悉的感觉熟悉的味道
 python3 setup.py build

 Traceback (most recent call last):
  File "setup.py", line 13, in <module>
    from setup_posix import get_config
  File "/usr/local/MySQL-python-1.2.5/setup_posix.py", line 2, in <module>
    from ConfigParser import SafeConfigParser

上面报错后,找到安装包目录,编辑setup_posix.py

from ConfigParser import SafeConfigParser
# 改为小写的
from configparser import SafeConfigParser

继续报错,找不到mysql_config

 python3 setup.py build
/bin/sh: /usr/local/bin/mysql_config: No such file or directory
Traceback (most recent call last):
  File "setup.py", line 17, in <module>
    metadata, options = get_config()
  File "/usr/local/MySQL-python-1.2.5/setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File "/usr/local/MySQL-python-1.2.5/setup_posix.py", line 25, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: /usr/local/bin/mysql_config not found

本地查找mysql_config,并修改安装包里的文件

  1. 修改setup_posix.py中的mysql_config.path为你mysql安装目录的mysql_config路径
  2. 修改site.cfg中的threadsafe = False,去掉mysql_config前的注释,并改为mysql_config = /usr/bin/mysql_config(你自己的路径)
find -name mysql_config
./usr/bin/mysql_config

继续python3 setup.py build,如果报错自己仔细看下

#继续build
python3 setup.py build

running build
running build_py
creating build
creating build/lib.linux-x86_64-3.7
copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.7
creating build/lib.linux-x86_64-3.7/MySQLdb
....

build完后直接安装python3 setup.py install

python3 setup.py install
running install
running bdist_egg
running egg_info
writing MySQL_python.egg-info/PKG-INFO
writing dependency_links to MySQL_python.egg-info/dependency_links.txt
writing top-level names to MySQL_python.egg-info/top_level.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

到此安装是完成了,报错格式错误,估计是版本匹配类问题,以后再看了

....
  File "/root/training/Python-3.7.0/lib/python3.7/site-packages/MySQL_python-1.2.5-py3.7-linux-x86_64.egg/MySQLdb/connections.py", line 36
    raise errorclass, errorvalue
                    ^
SyntaxError: invalid syntax

  File "/root/training/Python-3.7.0/lib/python3.7/site-packages/MySQL_python-1.2.5-py3.7-linux-x86_64.egg/MySQLdb/cursors.py", line 191
    except TypeError, m:
                    ^
SyntaxError: invalid syntax
# 格式错误,后面再看了

Installed /root/training/Python-3.7.0/lib/python3.7/site-packages/MySQL_python-1.2.5-py3.7-linux-x86_64.egg
Processing dependencies for MySQL-python==1.2.5
Finished processing dependencies for MySQL-python==1.2.5

你可能感兴趣的:(Python)