2

I am getting below error when I try to install MySQL client using the command "pip3 install mysqlclient".

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

Can anybody help me to solve this error? Thanks

3 Answers 3

3

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

pip install MySQL-python

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

pip install mysql-connector-python

To install the pymysql package, type the following command:

pip install pymysql

Code sample

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()
Sign up to request clarification or add additional context in comments.

Comments

0

Ensure you have at least tried these commands.

  • pip install mysql
  • export PATH=$PATH:/usr/local/mysql/bin
  • pip install MySQL-Python
  • Commands are run a root or sudo.

If nothing has changed. One of these solutions might help:

  1. Try running which mysql_config from bash. If it can't be found, run: locate mysql_config. The file path to the binary needs to be in the $PATH environment variable or specified in setup.py for the (what is now) missing module.

  2. You could try installing different packages. There is: mysql-connector-python or libmysqlclient-dev. The python-dev might help.

  3. Attempt to find the directory and files mysql/bin, mysql_config, and MySQL-Python and add their locations to $PATH.

EDIT: There are a couple solutions to try:

  • apt-get install python-mysqldb
  • Debian/Ubuntu: sudo apt-get install libmysqlclient-dev
  • Debian/Ubuntu (2018): sudo apt install default-libmysqlclient-dev
  • XAMPP (OP specified): export PATH=$PATH:/Applications/XAMPP/xamppfiles/bin

7 Comments

As i have mentioned i have installed xampp and have mysql installed under xampp. I am following this link stackoverflow.com/questions/10845839/….
I am trying it with scrapy.
I assume you're running Debian/Linux? If so, you're missing the package. If you're running the latest distro (2018 >) then try sudo apt install default-libmysqlclient-dev. Otherwise, sudo apt-get install libmysqlclient-dev, should work just fine. :)
I am using mac 10.13
If you have Homebrew installed, it couldn't hurt to try brew install mysql. To install Homebrew, open up a terminal and run /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)".
|
0

I have M1 processor in mac, and it solves my problem:

Install brew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install mysql with brew: arch -arm64 brew install mysql

Try install again with pip install mysql

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.