您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python 2.7 安装mysql-python 遇到的错误

bubuko 2022/1/25 20:09:30 mysql 字数 23475 阅读 1066 来源 http://www.bubuko.com/infolist-5-1.html

先说解决办法: 操作系统需安装如下RPM 1. yum install python-devel2. yum install mysql-devel 3. 安装mysql客户端(略) pip install MySQL-python -i http://pypi.douban.com/simple/ ...

先说解决办法:

操作系统需安装如下RPM

1. yum install python-devel
2. yum install mysql-devel

3. 安装mysql客户端(略)

 

pip install MySQL-python -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

 

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. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: http://pypi.douban.com/simple/
WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with --trusted-host pypi.douban.com.
ERROR: Could not find a version that satisfies the requirement MySQL-python (from versions: none)
ERROR: No matching distribution found for MySQL-python
[root@testdb01 local]# pip install MySQL-python -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
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. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: http://pypi.douban.com/simple/
Collecting MySQL-python
  Downloading http://pypi.doubanio.com/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108 kB)
     |████████████████████████████████| 108 kB 12.1 MB/s 
Building wheels for collected packages: MySQL-python
  Building wheel for MySQL-python (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python -u -c import sys, setuptools, tokenize; sys.argv[0] = ‘""‘/tmp/pip-install-bp0F0o/MySQL-python/setup.py‘""‘; __file__=‘""‘/tmp/pip-install-bp0F0o/MySQL-python/setup.py‘""‘;f=getattr(tokenize, ‘""‘open‘""‘, open)(__file__);code=f.read().replace(‘""‘\r\n‘""‘, ‘""‘\n‘""‘);f.close();exec(compile(code, __file__, ‘""‘exec‘""‘)) bdist_wheel -d /tmp/pip-wheel-ccIe4O
       cwd: /tmp/pip-install-bp0F0o/MySQL-python/
  Complete output (30 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
  creating build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
  creating build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  running build_ext
  building _mysql extension
  creating build/temp.linux-x86_64-2.7
  gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,final,1) -D__version__=1.2.5 -I/usr/local/mysql/include -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
  _mysql.c:29:20: fatal error: Python.h: No such file or directory
   #include "Python.h"
                      ^
  compilation terminated.
  error: command gcc failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for MySQL-python
  Running setup.py clean for MySQL-python
Failed to build MySQL-python
Installing collected packages: MySQL-python
    Running setup.py install for MySQL-python ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -u -c import sys, setuptools, tokenize; sys.argv[0] = ‘""‘/tmp/pip-install-bp0F0o/MySQL-python/setup.py‘""‘; __file__=‘""‘/tmp/pip-install-bp0F0o/MySQL-python/setup.py‘""‘;f=getattr(tokenize, ‘""‘open‘""‘, open)(__file__);code=f.read().replace(‘""‘\r\n‘""‘, ‘""‘\n‘""‘);f.close();exec(compile(code, __file__, ‘""‘exec‘""‘)) install --record /tmp/pip-record-7pF4Rv/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python2.7/MySQL-python
         cwd: /tmp/pip-install-bp0F0o/MySQL-python/
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
    creating build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    running build_ext
    building _mysql extension
    creating build/temp.linux-x86_64-2.7
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,final,1) -D__version__=1.2.5 -I/usr/local/mysql/include -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
    _mysql.c:29:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    error: command gcc failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python -u -c import sys, setuptools, tokenize; sys.argv[0] = ‘""‘/tmp/pip-install-bp0F0o/MySQL-python/setup.py‘""‘; __file__=‘""‘/tmp/pip-install-bp0F0o/MySQL-python/setup.py‘""‘;f=getattr(tokenize, ‘""‘open‘""‘, open)(__file__);code=f.read().replace(‘""‘\r\n‘""‘, ‘""‘\n‘""‘);f.close();exec(compile(code, __file__, ‘""‘exec‘""‘)) install --record /tmp/pip-record-7pF4Rv/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python2.7/MySQL-python Check the logs for full command output.

>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: libmysqlclient.so.20: cannot open shared object file: No such file or directory

 

import报错时,需手工指定lib:

ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20

python 2.7 安装mysql-python 遇到的错误

原文:https://www.cnblogs.com/turbodog/p/12380321.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶