I am using python3 to install mysql-python package. So, when I run
pip install mysql-python,
it gives me error.
Tried using
pip install --upgrade setuptools
It shows
Collecting mysql-python
Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-tu6ygqzj/mysql-python/setup.py", line 13, in <module>
from setup_posix import get_config
File "/tmp/pip-build-tu6ygqzj/mysql-python/setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
**ImportError: No module named 'ConfigParser'**
----------------------------------------
***Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-tu6ygqzj/mysql-python/***
Successfully installed with all files in it.
I guess you need to install the following:
pip install mysqlclient
In Python 3, ConfigParser has been renamed to configparser for PEP 8 compliance.
mysqlclient is a fork of mysql-python, with Python 3 support.
Kindly make sure you have installed the following before installing mysqlclient:
sudo apt-get install python3-dev libmysqlclient-dev
For Lunix and Mac Machines, install the mysqlclient pre-requisites via:
Debian / Ubuntu - sudo apt-get install python-dev default-libmysqlclient-dev
Red Hat / CentOS - sudo yum install python-devel mysql-devel
macOS (Homebrew) - brew install mysql-client
I tried to do this before that so after this it command work:
apt-get install libmysqlclient-dev
Trying to install from pipenv with:
pipenv install mysqlclient
will reseult in:
Installing mysqlclient… Collecting mysqlclient Using cached
https://files.pythonhosted.org/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-install-5vhtqgve/mysqlclient/setup.py", line 17, in
metadata, options = get_config()
File "/tmp/pip-install-5vhtqgve/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-install-5vhtqgve/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
----------------------------------------
Error: An error occurred while installing mysqlclient! Command
"python setup.py egg_info" failed with error code 1 in
/tmp/pip-install-5vhtqgve/mysqlclient/
This is likely caused by a bug in mysqlclient. Report this to its
maintainers.
I'm using a Debian and with another virtualenv it get the system package
python-mysqldb/testing,now 1.3.10-1 amd64
Pipenv won't use this one and won't install the other.
How can I solve this?
Thanks,BR
You probably need the mysql client lib for the OS.
sudo apt install libmysqlclient-dev
Then you should be able to:
pipenv install mysqlclient
I fixed that problem with the following command:
brew install mysql
First install python-dev
sudo apt-get install python3-dev
and then install mysqlclient-dev version
sudo apt-get install python3-dev libmysqlclient-dev
I would recommend you to install the file first.
On windows I used
pip install "mysqlclient-1.3.13-cp35-cp35m-win_amd64.whl"
and the tried:
pip install mysqlclient.
It worked well.
if you are on Centos
Try: yum install mariadb-devel
this package includes the missing mysql-config
Try:
sudo apt-get install libmysqlclient-dev
and then:
sudo apt-get install libmariadbclient-dev
I'm trying to install mysqlclient to connect to my database with django, but get the following error:
(venv) dhcp-ccc-12919:project user$ pip3 install mysqlclient
Collecting mysqlclient
Using cached https://files.pythonhosted.org/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/l4/0f1p1xlj3hlbxr6rzgqzrxmh0000gn/T/pip-install-lo7y8khq/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/l4/0f1p1xlj3hlbxr6rzgqzrxmh0000gn/T/pip-install-lo7y8khq/mysqlclient/setup_posix.py", line 54, in get_config
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/l4/0f1p1xlj3hlbxr6rzgqzrxmh0000gn/T/pip-install-lo7y8khq/mysqlclient/setup_posix.py", line 54, in <listcomp>
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/l4/0f1p1xlj3hlbxr6rzgqzrxmh0000gn/T/pip-install-lo7y8khq/mysqlclient/setup_posix.py", line 12, in dequote
if s[0] in "\"'" and s[0] == s[-1]:
IndexError: string index out of range
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/l4/0f1p1xlj3hlbxr6rzgqzrxmh0000gn/T/pip-install-lo7y8khq/mysqlclient/
I have the following in my settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'todo',
'USER': 'root',
'PASSWORD': 'password'
}
}
If you see the document of mysqlclient, I think it make mighty help for you.
The document say:
Note that this is a basic step. I can not support complete step for build for all environment. If you can see some error, you should fix it by yourself, or ask for support in some user forum. Don't file a issue on the issue tracker.
You may need to install the Python 3 and MySQL development headers and libraries like so:
$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential # Debian / Ubuntu
$ sudo yum install python3-devel mysql-devel # Red Hat / CentOS
Then you can install mysqlclient via pip now:
$ pip install mysqlclient
If you are on windows,
you can install mysqlclient using wheel from here.
Donwload the appropriate file as per your platform; for eg: if you are using python 3.6 and 32 bit python then download
mysqlclient‑1.3.13‑cp36‑cp36m‑win32.whl
After downloading it, copy it in C:/
Then install the file using following code:
pip3 install C:\mysqlclient‑1.3.13‑cp36‑cp36m‑win32.whl\
If you are using a virtual environment, then activate your virtual env before installing.
brew install mysql
fixed this for me
Please visit the following link which contains working pip installations for different os:
https://github.com/prasad01dalavi/python_packages_installations
for python2 in linux
sudo apt-get install -y python-dev libmysqlclient-dev && sudo pip install mysqlclient
I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is sh: mysql_config: not found
Could someone advice me on what to do?
rmicro#ubuntu:~$ pip install MySQL-python
Downloading/unpacking MySQL-python
Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
Running setup.py egg_info for package MySQL-python
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/rmicro/build/MySQL-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/rmicro/build/MySQL-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command python setup.py egg_info failed with error code 1
On Ubuntu it is advised to use the distributions repository. So installing python-mysqldb should be straight forward:
sudo apt-get install python-mysqldb
If you actually want to use pip to install, which is as mentioned before not the suggested path but possible, please have a look at this previously asked question and answer: pip install mysql-python fails with EnvironmentError: mysql_config not found
Here is a very comprehensive guide by the developer: http://mysql-python.blogspot.no/2012/11/is-mysqldb-hard-to-install.html
To get all the prerequisites for python-mysqld to install it using pip (which you will want to do if you are using virtualenv), run this:
sudo apt-get install build-essential python-dev libmysqlclient-dev
You have 2 options, as described bellow:
Distribution package like Glaslos suggested:
# sudo apt-get install python-mysqldb
In this case you can't use virtualenv no-site-packages (default option)
but must use:
# virtualenv --system-site-packages myenv
Use clean virtualenv and build your own python-mysql package.
First create virtualenv:
# virtualenv myvirtualenv
# source myvirtualenv/bin/activate
Then install build dependencies:
# sudo apt-get build-dep python-mysqldb
Now you can install python-mysql
# pip install mysql-python
NOTE Ubuntu package is python-mysql*db* , python pypi package is python-mysql (without db)
yum install mysql-devel
It worked for me.
Reread the error message. It says:
sh: mysql_config: not found
If you are on Ubuntu Natty, mysql_config belongs to package libmysqlclient-dev
Python or Python3 with MySQL, you will need these. These libraries use MySQL's connector for C and Python (you need the C libraries installed as well), which overcome some of the limitations of the mysqldb libraries.
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-mysql.connector
sudo apt-get install python3-mysql.connector
find the folder: sudo find / -name "mysql_config" (assume it's "/opt/local/lib/mysql5/bin")
add it into PATH:export PATH:export PATH=/opt/local/lib/mysql5/bin:$PATH
install it again
this worked for me on python 3
pip install mysqlclient
In python3 with virtualenv on a Ubuntu Bionic machine the following commands worked for me:
sudo apt install build-essential python-dev libmysqlclient-dev
sudo apt-get install libssl-dev
pip install mysqlclient
This is the error I get
(mysite)zjm1126#zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python
Downloading/unpacking mysql-python
Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
Running setup.py egg_info for package mysql-python
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log
(mysite)zjm1126#zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python
Downloading/unpacking mysql-python
Running setup.py egg_info for package mysql-python
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log
What can I do to resolve this?
It seems mysql_config is missing on your system or the installer could not find it.
Be sure mysql_config is really installed.
For example on Debian/Ubuntu you must install the package:
sudo apt-get install libmysqlclient-dev
Maybe the mysql_config is not in your path, it will be the case when you compile by yourself
the mysql suite.
Update: For recent versions of debian/ubuntu (as of 2018) it is
sudo apt install default-libmysqlclient-dev
In Mac OS, I simply ran this in terminal to fix:
export PATH=$PATH:/usr/local/mysql/bin
This is the quickest fix I found - it adds it to the path, but I think you're better off adding it permanently (ie add it to /etc/paths) if you plan to install MySQL-python in another environment.
(tested in OSX Mountain Lion)
There maybe various answers for the above issue, below is a aggregated solution.
For Ubuntu:
$ sudo apt update
$ sudo apt install python-dev
$ sudo apt install python-MySQLdb
For CentOS:
$ yum install python-devel mysql-devel
apt-get install libmysqlclient-dev python-dev
Seemed to do the trick.
If you are on MAC
Install this globally
brew install mysql
then export path like this
export PATH=$PATH:/usr/local/mysql/bin
Than globally or in your venv whatever you like
pip install MySQL-Python
Note: globally for python3 as Mac can have both python2 & 3
pip3 install MySQL-Python
You can use the MySQL Connector/Python
Installation via PyPip
pip install mysql-connector-python
Further information can be found on the MySQL Connector/Python 1.0.5 beta announcement blog.
On Launchpad there's a good example of how to add-, edit- or remove data with the library.
For centos users:
yum install -y mysql-devel python-devel python-setuptools
then
pip install MySQL-python
If this solution doesn't work, and print gcc compile error like:
_mysql.c:29:20: error: Python.h: No such file or directory
You need to specify the path of Python.h, like this:
pip install --global-option=build_ext --global-option="-I/usr/include/python2.6" MySQL-python
I was trying to install mysql-python on an Amazon EC2 Linux instance and I had to install these :
yum install mysql mysql-devel mysql-common mysql-libs gcc
But then I got this error :
_mysql.c:29:20: fatal error: Python.h: No such file or directory
So I installed :
yum install python-devel
And that did the trick.
For anyone that is using MariaDB instead of MySQL, the solution is to install the libmariadbclient-dev package and create a symbolic link to the config file with the correct name.
For example this worked for me:
ln -s /usr/bin/mariadb_config /usr/bin/mysql_config
For Linux
this works for me
yum install python-devel mysql-devel
Try sudo apt-get build-dep python-mysqldb
OSX Mavericks
Due to changes within osx mavericks & xcode development tools you may get the error on installation
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
therefore use :
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install mysql-python
for mariadb install libmariadbclient-dev instead of libmysqlclient-dev
sudo apt-get install libmariadbclient-dev
You should install the mysql first:
yum install python-devel mysql-community-devel -y
Then you can install mysqlclient:
pip install mysqlclient
I had the same problem in the Terraform:light container. It is based on Alpine.
There you have to install mariadb-dev with:
apk add mariadb-dev
But that one is not enough because also all the other dependencies are missed:
apk add python2 py2-pip gcc python2-dev musl-dev
sometimes the error depends on the actual cause. we had a case where mysql-python was installed through the python-mysqldb debian package.
a developer who didn't know this, accidentally ran pip uninstall mysql-python and then failed to recover with pip install mysql-python giving the above error.
pip uninstall mysql-python had destroyed the debian package contents, and of course pip install mysql-python failed because the debian package didn't need any dev files.
the correct solution in that case was apt-get install --reinstall python-mysqldb which restored mysql-python to its original state.
Sequence to be followed.
pip install mysqlclient
sudo apt-get install python3-dev libmysqlclient-dev
pip install configparser
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py
Then try to install the MYSQL-python again. That Worked for me
On Mac:
brew install mysql-client
locate mysql
mdfind mysql | grep bin
then add to path
export PATH=$PATH:/usr/local/Cellar/mysql-client/8.0.23/bin/
or permanently
echo "export PATH=$PATH:/usr/local/Cellar/mysql-client/8.0.23/bin/" >> ~/.zshrc
source ~/.zshrc
Had a similar issue trying to install on OS X Server 10.6.8. Here's what I had to do.
Using:
MySQL-python 1.2.4b4 (source)
MySQL-5.6.19 (binary installer)
Python 2.7 (binary installer)
NOTE: Installing in virtualenv...
Unzip source, open 'distribute_setup.py' and edit DEFAULT_VERSION to use the latest version of distribute tools, like so:
DEFAULT_VERSION = "0.6.49"
Save. Open 'site.cfg' file and uncomment the path to mysql_config so it looks something like (reference your own path to mysql_config):
# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = /usr/local/mysql/bin/mysql_config
Now clean, build and make will not fail with the 'mysql_config' not found error.
Hope this helps someone else trying to make use of their old xserves :-)
Your sudo path does not know about your local path... go into superuser mode, add the path, and install it from there.
sudo su
export PATH=$PATH:/usr/local/mysql/bin/
pip install mysql-python
exit
And you're up and running on OSX. Now you have an updated global python.
if you install MySQL-python in your virtual env, you should check the pip version, if the version is older than 9.0.1, please update it
pip install --upgrade pip
write on 27 Aug, 2021
my macos version is BigSur(14.4), and mysql version is mysql8. It seems like in the higher version of mysql, they delete the my_config.h files but change to the mysql.h.
so your guys should run the following shell:
cd /usr/local/include/mysql
cp mysql.h my_config.h
after that, run pip install MySQL-python and everything will be ok.
on MacOS Mojave, mysql_config is found at /usr/local/bin/ rather than /usr/local/mysql/bin as pointed above, so no need to add anything to path.
In my case my database is running on container and my flask app is running on another container when i tried updating code app got broke with error
Complete output from command python setup.py egg_info:
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-bya8e734/mysqlclient/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-build-bya8e734/mysqlclient/setup_posix.py", line 65, in get_config
libs = mysql_config("libs")
File "/tmp/pip-build-bya8e734/mysqlclient/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
Key in stack trace is
/bin/sh: 1: mysql_config: not found
because where my flask app is running doesn't have mysql client properly configured so first i installed mysql server and then install
sudo apt-get install mysql-server-5.7 -y
Then started MySQL
mansoor#LARC-mansur:~/Documents/clients/HR/DevopsSimulator/web$ sudo systemctl start mysql
Then install flask-mysql package and this time it worked
mansoor#LARC-mansur:~/Documents/clients/HR/DevopsSimulator/web$ sudo pip3 install flask-mysqldb
This is different case but posting here because may be someone else in the world facing same issue