日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

linux mysql python包_03_mysql-python模块, linux环境下python2,python3的

發布時間:2025/3/8 数据库 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux mysql python包_03_mysql-python模块, linux环境下python2,python3的 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

---恢復內容開始---

1、Python2 正常

[root@IP ~]#pip install mysql-python

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.

Requirement already satisfied: mysql-python in /usr/lib64/python2.7/site-packages (1.2.5)#測試

[root@IP ~]#python2

Python 2.7.5 (default, Aug 7 2019, 00:51:29)

[GCC4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2

Type"help", "copyright", "credits" or "license" formore information.>>> importMySQLdb>>>

有時候,上面的包安裝好了,導入失敗

另外的

[root@IP ~]#pip install mysqlclient

[root@IP~]#pip list

mysqlclient 1.4.6

#成功

[root@IP ~]#python

Python 2.7.5 (default, Aug 7 2019, 00:51:29)

[GCC4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2

Type"help", "copyright", "credits" or "license" formore information.>>> importMySQLdb>>>

2、說明

python2中支持?MySQLdb

python3為PyMySQL或

python3中mysqldb不再支持,包括mysql-python是安裝不上的。

轉為Pymysql

命令:

pip3 install PyMySQL

使用及安裝參考鏈接:

3、python3安裝PyMySQL

[root@IP mysqlclient-1.4.6]#pip3 install PyMySQL

[root@IP mysqlclient-1.4.6]#python3

Python 3.6.8 (default, Apr 25 2019, 21:02:35)

[GCC4.8.5 20150623 (Red Hat 4.8.5-36)] on linux

Type"help", "copyright", "credits" or "license" formore information.>>> import pymysql

4、python3 安裝?mysqlclient

失敗1

[root@localhost ~]#pip3 install mysqlclient

WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.

Collecting mysqlclient

Using cached https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz

Complete outputfromcommand python setup.py egg_info:/bin/sh: mysql_config: command notfound/bin/sh: mariadb_config: command notfound/bin/sh: mysql_config: command notfound

Traceback (most recent call last):

File"", line 1, in File"/tmp/pip-build-bpt1pa2k/mysqlclient/setup.py", line 16, in metadata, options=get_config()

File"/tmp/pip-build-bpt1pa2k/mysqlclient/setup_posix.py", line 61, inget_config

libs= mysql_config("libs")

File"/tmp/pip-build-bpt1pa2k/mysqlclient/setup_posix.py", line 29, inmysql_configraise EnvironmentError("%s not found" %(_mysql_config_path,))

OSError: mysql_confignotfound----------------------------------------Command"python setup.py egg_info" failed with error code 1 in /tmp/pip-build-bpt1pa2k/mysqlclient/

按照網上

更新pip3 和 setuptools

[root@localhost ~]#pip3 install --upgrade setuptools

[root@localhost ~]#python3 -m pip install --upgrade pip

繼續失敗

[root@localhost ~]#pip3 install mysqlclient

Traceback (most recent call last):

File"/usr/bin/pip3", line 16, in sys.exit(main())

TypeError:'module' object is not callable

安裝mysql依賴

yum install mysql-devel gcc gcc-devel python-devel

繼續安裝

[root@localhost ~/mysqlclient-1.4.6]#python3 setup.py install

[Errno 2] No such file ordirectory:'/usr/local/lib64/python3.6/site-packages/test-easy-install-35198.write-test'The installation directory you specified (via--install-dir, --prefix, orthe distutils default setting) was:/usr/local/lib64/python3.6/site-packages/This directory doesnot currently exist. Please create it and try again, orchoose a different installation directory (using the-d or --install-dir

option).

報錯

創建該目錄

失敗1.1

deepin失敗

/bin/sh: 1: mysql_config: not found

Traceback (most recent call last):

File"setup.py", line 16, in metadata, options=get_config()

File"/home/redhat/Desktop/pycharmProject/base-api/mysqlclient-1.4.6/setup_posix.py", line 61, inget_config

libs= mysql_config("libs")

File"/home/redhat/Desktop/pycharmProject/base-api/mysqlclient-1.4.6/setup_posix.py", line 29, inmysql_config

raise EnvironmentError("%s not found" %(_mysql_config_path,))

OSError: mysql_config not found

安裝這個,找不到,

sudo apt-get install libmysqlclient-dev

更新apt源試試

然后可以安裝成功

失敗2

使用pip install mysqlclient命令安裝mysqlclient失敗?

安裝mysqlclient報錯如下

1、下載本地whl,安裝

blog:https://blog.csdn.net/cn_1937/article/details/81533544

https://blog.csdn.net/liuweiyuxiang/article/details/80666773

#下載包

[root@IP mysqlclient-1.4.6]#wget

https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz#解壓

[root@IP ~]#tar xvf mysqlclient-1.4.6.tar.gz

#安裝保存 缺少gcc

[root@IP mysqlclient-1.4.6]#python3 setup.py install

MySQLdb/_mysql.c:38:20: fatal error: Python.h: No such file ordirectory#include "Python.h"

^compilation terminated.

error: command'gcc' failed with exit status 1

2、安裝python3-devel

#安裝成功依賴

[root@IP mysqlclient-1.4.6]#yum install python3-devel

重裝成功

[root@IP mysqlclient-1.4.6]#python3 setup.py install

或者

[root@IP mysqlclient-1.4.6]#pip3 install mysqlclient

導入有問題

#導入有問題

[root@IP mysqlclient-1.4.6]#python3

Python 3.6.8 (default, Aug 7 2019, 17:28:10)

[GCC4.8.5 20150623 (Red Hat 4.8.5-39)] on linux

Type"help", "copyright", "credits" or "license" formore information.>>> importMySQLdb

Traceback (most recent call last):

File"", line 1, in File"/root/mysqlclient-1.4.6/MySQLdb/__init__.py", line 18, in

from . import_mysql

ImportError: cannotimport name '_mysql'

3、MySQLdb導入問題

在包安裝的時候,會默認在包下的路徑,error

---恢復內容結束---

總結

以上是生活随笔為你收集整理的linux mysql python包_03_mysql-python模块, linux环境下python2,python3的的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。