如何从xampp到python3使用mysql?

pbgvytdp  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(361)

当我尝试使用命令“pip3installmysqlclient”安装mysql客户机时,出现以下错误。

Complete output from command python setup.py egg_info:
    /bin/sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/l1/f1klm_s92g53c9v2p1vrdwg80000gn/T/pip-install-a0t6svmj/mysqlclient/setup.py", line 18, in <module>
        metadata, options = get_config()
      File "/private/var/folders/l1/f1klm_s92g53c9v2p1vrdwg80000gn/T/pip-install-a0t6svmj/mysqlclient/setup_posix.py", line 53, in get_config
        libs = mysql_config("libs_r")
      File "/private/var/folders/l1/f1klm_s92g53c9v2p1vrdwg80000gn/T/pip-install-a0t6svmj/mysqlclient/setup_posix.py", line 28, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    OSError: mysql_config not found

xampp公司version:- 7.2.3.0 python:- 3.7
有人能帮我解决这个错误吗?谢谢

hsvhsicv

hsvhsicv1#

确保您至少尝试过这些命令。 pip install mysql export PATH=$PATH:/usr/local/mysql/bin pip install MySQL-Python 命令是运行 root 或者 sudo .
如果什么都没有改变。其中一种解决方案可能会有所帮助:
试着跑步 which mysql_config 来自bash。如果找不到,请运行: locate mysql_config . 二进制文件的文件路径需要在$path环境变量中或在中指定 setup.py 对于(现在的)缺失模块。
你可以尝试安装不同的软件包。有: mysql-connector-python 或者 libmysqlclient-dev . 这个 python-dev 可能会有帮助。
尝试查找目录和文件 mysql/bin , mysql_config ,和 MySQL-Python 并将它们的位置添加到$path。
编辑:有几个解决方案可以尝试: apt-get install python-mysqldb debian/ubuntu版本: sudo apt-get install libmysqlclient-dev debian/ubuntu(2018年): sudo apt install default-libmysqlclient-dev xampp(指定op): export PATH=$PATH:/Applications/XAMPP/xamppfiles/bin

l0oc07j2

l0oc07j22#

要安装mysql python包,请键入以下命令:

pip install MySQL-python

要安装mysql connector python包,请键入以下命令:

pip install mysql-connector-python

要安装pymysql包,请键入以下命令:

pip install pymysql

代码示例

hostname = 'localhost'
username = 'USERNAME'
password = 'PASSWORD'
database = 'DBNAME'
def doQuery( conn ) :
cur = conn.cursor()

cur.execute( "SELECT fname, lname FROM employee" )
for firstname, lastname in cur.fetchall() :
    print firstname, lastname
print "Using MySQLdb…"
import MySQLdb
myConnection = MySQLdb.connect( host=hostname, user=username, passwd=password, db=database )
doQuery( myConnection )
myConnection.close()
print "Using pymysql…"
import pymysql
myConnection = pymysql.connect( host=hostname, user=username, passwd=password, db=database )
doQuery( myConnection )
myConnection.close()
print "Using mysql.connector…"
import mysql.connector
myConnection = mysql.connector.connect( host=hostname, user=username, passwd=password, db=database )
doQuery( myConnection )
myConnection.close()

相关问题