1

I installed mysql through XAMPP.

When I try pip install mysqlclient I get this error

MBP-of-admin:django_project aanto$ pip install mysqlclient
Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz
    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/jw/4xk541g14mq3ljnws61fbt_m0000gn/T/pip-install-0u41r1pb/mysqlclient/setup.py", line 16, in <module>
        metadata, options = get_config()
      File "/private/var/folders/jw/4xk541g14mq3ljnws61fbt_m0000gn/T/pip-install-0u41r1pb/mysqlclient/setup_posix.py", line 51, in get_config
        libs = mysql_config("libs")
      File "/private/var/folders/jw/4xk541g14mq3ljnws61fbt_m0000gn/T/pip-install-0u41r1pb/mysqlclient/setup_posix.py", line 29, in mysql_config
        raise EnvironmentError("%s not found" % (_mysql_config_path,))
    OSError: mysql_config not found

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/jw/4xk541g14mq3ljnws61fbt_m0000gn/T/pip-install-0u41r1pb/mysqlclient/

How can I solve?

  • Shows how to do what you want for Python 3 - stackoverflow.com/questions/51633002/…. – slm Apr 28 at 13:57
  • after several hours has been wasted, I gave up with XAMPP and installed mysql with brew – alfredopacino Apr 28 at 14:00
  • That's been my approach to this space as well, the *AMPP solutions are more of a liability to me than doing it via brew. The solution there isn't XAMPP specific though, it's shows how to setup MySQL connectors for Python generically. – slm Apr 28 at 14:03
1

I found this answer on StackOverflow titled: How to use MYSql from xampp for python 3?.

An answer there shows 3 ways to install the Python drivers/connectors for working with MySQL DBs.

method 1 - MySQL-python

To install the MySQL-python package, type the following command:

 $ pip install MySQL-python

Method 2 - mysql-connector-python

To install the mysql-connector-python package, type the following command:

$ pip install mysql-connector-python

Method 3 - pymysql

To install the pymysql package, type the following command:

$ pip install pymysql

Examples

$ cat mysql_connector_exs.py
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()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .