离线安装python2的MySQLdb

这篇具有很好参考价值的文章主要介绍了离线安装python2的MySQLdb。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

离线安装python2的MySQLdb

需求

环境:
centos7.9
pytthon2.7.5

安装MySQLdb模块

下载MySQLdb模块地址

直接安装报错如下

[root@localhost MySQL-python-1.2.5]# ls
doc      HISTORY  MANIFEST.in   _mysql.c  _mysql_exceptions.py   PKG-INFO       README.md  setup_common.py  setup.py          site.cfg
GPL-2.0  INSTALL  metadata.cfg  MySQLdb   MySQL_python.egg-info  pymemcompat.h  setup.cfg  setup_posix.py   setup_windows.py  tests
[root@localhost MySQL-python-1.2.5]# python setup.py build
sh: mysql_config: command not found
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

解决报错需要安装python-devel mysql-devel 找个相同的环境下载这两个的rpm离线包
配置阿里yum源

wget http://mirrors.aliyun.com/repo/Centos-7.repo
清理缓存
[root@localhost yum.repos.d]# sudo yum clean all
[root@localhost yum.repos.d]# sudo yum makecache

1、下载python-devel mysql-devel安装包

[root@localhost yum.repos.d]# yum install --downloadonly --downloaddir=/root/devel/ python-devel mysql-devel
[root@localhost yum.repos.d]# cd /root/devel/

[root@localhost devel]# ls
e2fsprogs-1.42.9-19.el7.x86_64.rpm          krb5-libs-1.15.1-50.el7.x86_64.rpm         libselinux-devel-2.5-15.el7.x86_64.rpm  mariadb-devel-5.5.68-1.el7.x86_64.rpm   python-devel-2.7.5-89.el7.x86_64.rpm
e2fsprogs-libs-1.42.9-19.el7.x86_64.rpm     libcom_err-1.42.9-19.el7.x86_64.rpm        libsepol-devel-2.5-10.el7.x86_64.rpm    openssl-devel-1.0.2k-19.el7.x86_64.rpm  python-libs-2.7.5-89.el7.x86_64.rpm
keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm  libcom_err-devel-1.42.9-19.el7.x86_64.rpm  libss-1.42.9-19.el7.x86_64.rpm          python-2.7.5-89.el7.x86_64.rpm          python-rpm-macros-3-34.el7.noarch.rpm
krb5-devel-1.15.1-50.el7.x86_64.rpm         libkadm5-1.15.1-50.el7.x86_64.rpm          libverto-devel-0.2.5-4.el7.x86_64.rpm   python2-rpm-macros-3-34.el7.noarch.rpm  python-srpm-macros-3-34.el7.noarch.rpm

2、强制不校验安装python-devel mysql-devel

[root@localhost devel]# rpm -ivh *.rpm --force
error: Failed dependencies:
	python < 2.7.5-89.el7 conflicts with python-devel-2.7.5-89.el7.x86_64
[root@localhost devel]# rpm -ivh *.rpm --force --nodeps
Preparing...                          ################################# [100%]
Updating / installing...
   1:libcom_err-1.42.9-19.el7         ################################# [  5%]
   2:krb5-libs-1.15.1-50.el7          ################################# [ 10%]
   3:python-libs-2.7.5-89.el7         ################################# [ 15%]
   4:python-2.7.5-89.el7              ################################# [ 20%]
   5:libkadm5-1.15.1-50.el7           ################################# [ 25%]
   6:e2fsprogs-libs-1.42.9-19.el7     ################################# [ 30%]
   7:libcom_err-devel-1.42.9-19.el7   ################################# [ 35%]
   8:libss-1.42.9-19.el7              ################################# [ 40%]
   9:python-srpm-macros-3-34.el7      ################################# [ 45%]
  10:python-rpm-macros-3-34.el7       ################################# [ 50%]
  11:python2-rpm-macros-3-34.el7      ################################# [ 55%]
  12:libverto-devel-0.2.5-4.el7       ################################# [ 60%]
  13:libsepol-devel-2.5-10.el7        ################################# [ 65%]
  14:libselinux-devel-2.5-15.el7      ################################# [ 70%]
  15:keyutils-libs-devel-1.5.8-3.el7  ################################# [ 75%]
  16:krb5-devel-1.15.1-50.el7         ################################# [ 80%]
  17:openssl-devel-1:1.0.2k-19.el7    ################################# [ 85%]
  18:mariadb-devel-1:5.5.68-1.el7     ################################# [ 90%]
  19:python-devel-2.7.5-89.el7        ################################# [ 95%]
  20:e2fsprogs-1.42.9-19.el7          ################################# [100%]

再次回到MySQL-python-1.2.5目录下

3、安装MySQL-python-1.2.5

[root@localhost MySQL-python-1.2.5]# python setup.py build
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/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
gcc -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64/mysql -L/usr/lib64 -lmysqlclient -lpthread -lz -lm -ldl -lssl -lcrypto -lpython2.7 -o build/lib.linux-x86_64-2.7/_mysql.so

可以看到不报错了,接着安装模块文章来源地址https://www.toymoban.com/news/detail-803813.html

root@localhost MySQL-python-1.2.5]# python setup.py install
running install
running bdist_egg
running egg_info
/usr/lib/python2.7/site-packages/setuptools/command/egg_info.py:177: PkgResourcesDeprecationWarning: Parameters to load are deprecated.  Call .resolve and .require separately.
  writer = ep.load(installer=installer)
writing MySQL_python.egg-info/PKG-INFO
writing top-level names to MySQL_python.egg-info/top_level.txt
writing dependency_links to MySQL_python.egg-info/dependency_links.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
running install_lib
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
running build_ext
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.7/_mysql_exceptions.py -> build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/converters.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/connections.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/cursors.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/MySQLdb/times.py -> build/bdist.linux-x86_64/egg/MySQLdb
creating build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/CR.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/ER.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/FLAG.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/REFRESH.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/constants/CLIENT.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
copying build/lib.linux-x86_64-2.7/MySQLdb/release.py -> build/bdist.linux-x86_64/egg/MySQLdb
copying build/lib.linux-x86_64-2.7/_mysql.so -> build/bdist.linux-x86_64/egg
byte-compiling build/bdist.linux-x86_64/egg/_mysql_exceptions.py to _mysql_exceptions.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/converters.py to converters.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/connections.py to connections.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/cursors.py to cursors.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/times.py to times.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CR.py to CR.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/ER.py to ER.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FLAG.py to FLAG.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc
byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/release.py to release.pyc
creating stub loader for _mysql.so
byte-compiling build/bdist.linux-x86_64/egg/_mysql.py to _mysql.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/MySQL_python-1.2.5-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing MySQL_python-1.2.5-py2.7-linux-x86_64.egg
Copying MySQL_python-1.2.5-py2.7-linux-x86_64.egg to /usr/lib64/python2.7/site-packages
Adding MySQL-python 1.2.5 to easy-install.pth file

Installed /usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg
Traceback (most recent call last):
  File "setup.py", line 21, in <module>
    setuptools.setup(**metadata)
  File "/usr/lib64/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib64/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/site-packages/setuptools/command/install.py", line 73, in run
    self.do_egg_install()
  File "/usr/lib/python2.7/site-packages/setuptools/command/install.py", line 101, in do_egg_install
    cmd.run()
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 380, in run
    self.easy_install(spec, not self.no_deps)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 604, in easy_install
    return self.install_item(None, spec, tmpdir, deps, True)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 655, in install_item
    self.process_distribution(spec, dist, deps)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 701, in process_distribution
    distreq.project_name, distreq.specs, requirement.extras
TypeError: __init__() takes exactly 2 arguments (4 given)

4、导入MySQLdb模块

[root@localhost MySQL-python-1.2.5]# python
Python 2.7.5 (default, Oct 14 2020, 14:45:30) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
/usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.pyc, but /root/MySQL-python-1.2.5 is being added to sys.path
>>> import MySQLdb
>>> import MySQLdb
>>> quit()

六级标题

到了这里,关于离线安装python2的MySQLdb的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Ubuntu上python2和python3安装配置

    Ubuntu 20.04 LTS已经移除Python2,默认安装python3。但是很多时候还是会经常用到python2.7版本,这里首先单独安装python2.7,然后配置python2和python3,以达到手动切换系统默认python版本。 1.安装python2.7 命令:sudo apt install python2,一路回车 2.配置系统默认python版本       依次执行以下命

    2024年02月13日
    浏览(42)
  • Centos8: 安装python2, 并设置默认版本

    2024年02月08日
    浏览(49)
  • Kali Python2.7安装pip2和模块方法

    kali的python2官方说不维护和更新了,但很多工具都是在python2.7环境下使用,下载模块需要用到pip2工具。 1. 安装setuptools-18.5 wget https://pypi.python.org/packages/source/s/setuptools/setuptools-18.5.tar.gz (这里我用windows下载到本地了,kali远程下载速度太慢!) tar -zxvf setuptools-18.5.tar.gz cd setu

    2023年04月20日
    浏览(36)
  • centos服务器系统下安装python3并与自带的python2

    在centos中,自带有python2,因此需要经常安装python3。但是这里有一个坑,就是centos的yum是用python2写的,如果正常编译安装python3,那么yum就会直接挂了。为了方便以后编译安装python3,不用天天去网上找教程仅供参考。 (因平台原因本文中www即为xxx ,com即为zzz,http/ccccc即为c

    2024年02月11日
    浏览(47)
  • 阿里云效Flow 添加自有主机安装Python2.7失败解决方案

    在添加自由主机时需执行提供的一段shell脚本,需要安装Python2.7 但安装Python2.7一直失败,解决方案如下 Python3.10.4 安装教程 Centos系统 自行解压 production-install.zip 原理:注释远程shell脚本中的检测Python版本函数 把执行远程的Shell 修改为 执行本地 (sh production-install.sh) 替换命令参

    2024年02月12日
    浏览(51)
  • python链接mysql报错:No module named MySQLdb

    尝试使用python链接mysql,把数据进行插入的时候,有报错: 然后: pip install mysqlclient 报错: https://codeantenna.com/a/n3yCa0VDpB,下载对应python版本 直接引入pymysql,虽然第一次引入,但是缺少初始化信息,需要整体引用 添加初始化后,就不会报错缺少mysqldb module了。

    2024年02月04日
    浏览(45)
  • 安装node-sass失败 或 npm install Error: not found: python2 解决方案

    1. 安装python2 可以用npm命令安装 也可以自行下载安装 Python 2.7 2. 安装完毕后配置环境变量 3.再配置一下版本 node-sass 实在太坑了,之前遇到安装失败使用方法一完美解决。最近又一次遇到了,但是方法一又无效了。于是我又在网上找到另一个方法,就是用 dart-sass 来替换 node

    2024年02月13日
    浏览(97)
  • Debian 系的 apt 离线安装工具和 Python pip 离线安装工具

    最近有个项目,服务器进去之后不能联网,装包什么的都不方便,于是用一天时间写了一个方便的工具,用于 Debian 和 Ubuntu 系包的离线安装,项目地址请点这里 github link. 两台服务器,一台 A 可以上网(最好网络好一点),一台 B 不能上网,保证 A 和 B 要具备相同架构,相同

    2024年02月11日
    浏览(44)
  • Python的离线安装

    原文链接 在没有外网的情况下,安装Python环境只能采用离线方式。 Python离线安装包的下载地址:https://www.python.org/ftp/python/ 我选择的是: python-3.8.5-amd64.exe 双击运行安装包即可完成安装。 安装完成后添加环境变量: 查看是否成功: 输出版本号 Python 3.8.5 即表示安装成功。

    2024年02月08日
    浏览(62)
  • python离线安装三方包

    还是得找一台能联网的电脑,一般这种都是linux环境。 (一) 创建依赖包,并cd到指定目录下 (二)通过pip(pip3)下载文件 如果系统中有python2,并且你安装了Python3还没修改配置环境变量,就加个3 当执行download之后就会在/lib里面存在.whl文件了 (三)拷贝到目标机器执行inst

    2024年02月09日
    浏览(26)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包