I'm trying to install MySQLdb for Python on Mac OS.
When I digit pip install MySQL-python shell returns to this:
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 "", line 1, in
File "/private/var/folders/9h/2lp9kx993ygbrfk1lxr0sz500000gq/T/pip-install-7xyyBe/MySQL-python/setup.py", line 17, in
metadata, options = get_config()
File "setup_posix.py", line 53, in get_config
libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
File "setup_posix.py", line 8, 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/9h/2lp9kx993ygbrfk1lxr0sz500000gq/T/pip-install-7xyyBe/MySQL-python/
What can I do? I searched everywhere but I couldn't find an answer.
(I had installed Python 2.7)
I fixed the error. If anyone have this error just follow these steps:
First of all install mysql connector
brew install mysql-connector-c
You have to modify lines in mysql_config (this is an alias)
vim /usr/local/bin/mysql_config
(I sincerely consider to open mysql_config with a file editor, you can find the
exact folder here)
/usr/local/Cellar/mysql-connector-c/6.1.11/bin/
Replace these lines.
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
should be:
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
Set environment variable
brew info openssl
it would tell what’s needed
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
For pkg-config to find this software you may need to set:
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
Then you can install MySQL
pip install MySQL-python
You can test if MySQL is installed with this:
python -c "import MySQLdb"
Hope this works also for you!
Related
Everytime I execute my python code, it gives me the above ModuleNotFound error when I execute with python3. With python, it gives me an ImportError.
I have updated setuptools using pip install --upgrade setuptools.
I have also tried multiple commands such as: pip install mysqlclient, pip install MySQL-python, pip install pymysql.
I have tried these commands with pip3 as well (Not sure if it makes a difference).
Everytime I try these commands, it gives me the following error:
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/0y/xsr1t8rs36l0vlq3_f2q42g40000gn/T/pip-install-soxlcjei/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "/private/var/folders/0y/xsr1t8rs36l0vlq3_f2q42g40000gn/T/pip-install-soxlcjei/mysqlclient/setup_posix.py", line 51, in get_config
libs = mysql_config("libs")
File "/private/var/folders/0y/xsr1t8rs36l0vlq3_f2q42g40000gn/T/pip-install-soxlcjei/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/0y/xsr1t8rs36l0vlq3_f2q42g40000gn/T/pip-install-soxlcjei/mysqlclient
How do I fix this? I am using a macOS High Sierra. I have gone through solutions for similar problems on ubuntu/debian systems and have to tried to apply it here. None of that works on a mac. Also, i already have mysql installed and it works perfectly. It is constantly running on my system.
you should download a tar named as Mysql-python-1.2.4b4.tar.gz, and unzip it, cd to the dir and update the file site.cfg: # mysql_config = /usr/local/mysql/bin/mysql_config to mysql_config = /usr/local/mysql/bin/mysql_config
and then python setup.py install, after you installed the mysql-python,then you can not get the error.
I am trying to install mysqlclient to my Python 3.6. Originally what i want to install is MySQLdb, however it was saying that MySQLdb does not work with Python 3 (still?). So i switch to mysqlclient.
pip3 install mysqlclient
However, it was given this error:
Collecting mysqlclient
Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.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/h3/sff7td1d6pg5v5qsm5xf31q80000gn/T/pip-install-ki9z7ln9/mysqlclient/setup.py", line 18, in <module>
metadata, options = get_config()
File "/private/var/folders/h3/sff7td1d6pg5v5qsm5xf31q80000gn/T/pip-install-ki9z7ln9/mysqlclient/setup_posix.py", line 60, in get_config
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/h3/sff7td1d6pg5v5qsm5xf31q80000gn/T/pip-install-ki9z7ln9/mysqlclient/setup_posix.py", line 60, in <listcomp>
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/h3/sff7td1d6pg5v5qsm5xf31q80000gn/T/pip-install-ki9z7ln9/mysqlclient/setup_posix.py", line 13, in dequote
raise Exception("Wrong MySQL configuration: maybe https://bugs.mysql.com/bug.php?id=86971 ?")
Exception: Wrong MySQL configuration: maybe https://bugs.mysql.com/bug.php?id=86971 ?
Can I know what should i do to solve this issue?
It's a bug since November 2017.
I had the same error and that's what helped:
Make changes to mysql_config file in mysqlclient-python or mysql-connector-c or libmysqlclient (depending on what you are using)
Change
# on macOS, on or about line 112:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
to:
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
Add following to the end of your .bash_profile how to do that:
export PATH="/usr/local/opt/openssl/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
Run pip install mysqlclient, that should work now.
For more info check this link, look at the "Note about bug of MySQL Connector/C on macOS" section.
Trying to follow a Django tutorial but I cannot install mysqlclient.
The tutorial claims that I can do so with the following command:
pip install mysqlclient
but this generates this error:
Collecting mysqlclient Using cached 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 "<string>", line 1, in <module>
File "/tmp/pip-build-rrolctwh/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-rrolctwh/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-rrolctwh/mysqlclient/setup_posix.py", line 26, 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 /tmp/pip-build-rrolctwh/mysqlclient/
I have the most up-to-date pip and virtualenv installed.
I would like to be able to install mysqlclient so that I may continue with the tutorial.
You should also install the mysql and python development headers and libraries:
https://github.com/PyMySQL/mysqlclient-python#prerequisites
I was facing the same problems, but following the instructions in the Official mysqlclient documentation fixed it for me
but just to clarify I was running python 3.5 from a virtual environment
and after installing the prerequisites, it all worked fine
The following solved it for me :
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
Source : https://github.com/PyMySQL/mysqlclient#prerequisites
I had also similar issue on Centos 6, where there was a problem with mysql migration to maria, I had some conflicts, but finally I installed:
yum list installed |grep MariaDB
MariaDB-client.x86_64 10.2.7-1.el6 #bull
MariaDB-common.x86_64 10.2.7-1.el6 #bull
MariaDB-compat.x86_64 10.2.7-1.el6 #bull
MariaDB-devel.x86_64 10.2.7-1.el6 #bull
MariaDB-server.x86_64 10.2.7-1.el6 #bull
And the issue was resolved.
This question already has answers here:
pip install mysql-python fails with EnvironmentError: mysql_config not found
(24 answers)
Closed 3 years ago.
I have been trying for a few days to fix this, looking at other questions but I can't find a question wth the same error that I am getting.
I have been attempting to follow this tutorial https://realpython.com/learn/start-django/ and get to this point:
Database settings
First, install MySQL-python, which is a database connector for Python:
$ pip install MySQL-python
Everything has worked okay up to here but when I try and install MySQL-python I get the following error:
(env) Camerons-MacBook-Pro:django15_project camrail$ pip install MySQL-python
Collecting MySQL-python
Using cached MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup_posix.py", line 25, 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 in /private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/
(env) Camerons-MacBook-Pro:django15_project camrail$
I found this answer https://opensourcehacker.com/2011/03/02/installing-mysql-python-connector-on-osx/ that says the MySQL utilities are not made available, so I followed their advice to fix it but to no avail. I have also tried installing developer tools xcode-select --install as some have suggested. I have tried reinstalling ez_setup.
Not really sure where to go from here, any help greatly appreciated.
In my opinions mysql_config is missing on your system or the installer could not find it. Please Be sure mysql_config is really installed.
For instance,
On Debian/Ubuntu, You must install the package:
sudo apt-get install libmysqlclient-dev
Running Mac OSX Mountain Lion, I simply ran this in terminal to fix:
export PATH=$PATH:/usr/local/mysql/bin
This is the quickest fix I found.
I was also getting the same error while installing the mysql package by pip But after installing libmysqlclient-dev
sudo apt install libmysqlclient-dev
pip install mysql
Now it worked for me..
verified:
import mysql
did not find any error, Means got installed successfully and working
properly
Check your mysql configuration file using this:
mysql_config
Now you should get an output something like this:
mysql_config
Usage: /usr/bin/mysql_config [OPTIONS]
Compiler: GNU 6.3.0
Options:
--cflags [-I/usr/include/mysql ]
--cxxflags [-I/usr/include/mysql ]
--include [-I/usr/include/mysql]
--libs [-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -latomic -ldl]
--libs_r [-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -latomic -ldl]
--plugindir [/usr/lib/mysql/plugin]
--socket [/var/run/mysqld/mysqld.sock]
--port [0]
--version [5.7.18]
--libmysqld-libs [-L/usr/lib/x86_64-linux-gnu -lmysqld -lpthread -lz -lm -lrt -latomic -lcrypt -ldl -laio -llz4 -lnuma]
--variable=VAR VAR is one of:
pkgincludedir [/usr/include/mysql]
pkglibdir [/usr/lib/x86_64-linux-gnu]
plugindir [/usr/lib/mysql/plugin]
Ideally it should contain libmysqld-libs option. If it is not there, as it was not there in my case, you can assume that your mysql is broken.
In this case you can write this configuration to config file directly
If you are using Windows OS download and install mysql-python directly from here .
Not sure if it useful. But it help me to solve the problem.
apt-get install build-essential zlib1g zlib1g-dev zlibc libxml2 libxml2-dev
For completeness sake, on Debian Stretch the pkg is now called default-libmysqlclient-dev.
sudo apt-get install default-libmysqlclient-dev
I run the following commands and it worked smooth in Ubuntu 17.10
sudo apt-get install libmysqlclient-dev
pip3 install mysqlclient
I use macports and I have successfully install mysql5 using macports, and my python also managed by macports. Currently I am trying to do pip install mysql-python on my virtualenv but I am getting an error which says, mysql_config not found:
~/code]$pip install mysql-python
Downloading/unpacking mysql-python
Running setup.py egg_info for package mysql-python
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "~/myVirtualEnv/build/mysql-python/setup.py", line 18, 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 25, 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: command not found
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "~/myVirtualEnv/build/mysql-python/setup.py", line 18, 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 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
I read many google examples but more I read helped me to confuse myself further.
Looks like macport have had a issue but it has been closed for while.. http://trac.macports.org/ticket/6982
MacPort creates a symbolic link mysql_config5 in /opt/local/bin to /opt/local/lib/mysql5/bin/mysql_config. Create another link called mysql_config.
cd /opt/local/bin
sudo ln -s /opt/local/lib/mysql5/bin/mysql_config .
I seem to recall having to create a my.cnf too. By default Mac OSX uses all the defaults and doesn't create a my.cnf, create one /etc/my.cnf, it can be trivial.
Mine is just:
[mysqld]
bind-address = 0.0.0.0
port = 3306
mysql_config is an executable that it is in the libmysqlclient package so you need to install. On Deb systems you could install this using
sudo apt-get install libmysqlclient-dev
in RPM
RPM equivalent: sudo yum install mysql-devel
in mac maybe
Macports - port install mysql5 +server
Add /opt/local/lib/mysql5/bin/ to your command search path and then rerun the "pip install" command should solve the problem.
export PATH=/opt/local/lib/mysql55/bin/:$PATH
pip install mysql-python
I encountered the same issue, and solved it:
Install mysql. If you have installed it, ignore this step.
yum install mysql-devel
If you encountered error like Python.h: No such file or directory,
run yum -y install python-devel