I am trying to get a Python script to run on the linux server I'm connected to via ssh. The script uses mysqldb. I have all the other components I need, but when I try to install mySQLdb via setuptools like so:,
python setup.py install
I get the following error report related to the mysql_config
command.
sh: mysql_config: command not found
Traceback (most recent call last):
File "setup.py", line 15, in <module>
metadata, options = get_config()
File "/usr/lib/python2.5/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/usr/lib/python2.5/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Has anyone else encountered this error and if so how did you resolve it/what can I do to successfully install mysqldb?
I fixed this problem with the following steps:
I had this issues and solved if by adding a symlink to
mysql_config
.I had installed mysql with homebrew and saw this in the output.
Depending on how you got
mysql
it will be in different places. In my case/usr/local/Cellar/mysql
Once you know where it is you should be able to ma a symbolic link to where python is looking for it.
/usr/local/mysql
This worked for me.
sudo apt-get install python-mysqldb
Python 2.5? Sounds like you are using a very old version of Ubuntu Server (Hardy 8.04?) - please confirm which Linux version the server uses.
python-mysql search on ubuntu package database
Some additional info:
From the README of mysql-python -
Red Hat Linux .............
MySQL-python is pre-packaged in Red Hat Linux 7.x and newer. This includes Fedora Core and Red Hat Enterprise Linux. You can also build your own RPM packages as described above.
Debian GNU/Linux ................
Packaged as
python-mysqldb
_::Or use Synaptic.
.. _
python-mysqldb
: http://packages.debian.org/python-mysqldbUbuntu ......
Same as with Debian.
Footnote: If you really are using a server distribution older than Ubuntu 10.04 then you are out of official support, and should upgrade sooner rather than later.
This method is only for those who know that Mysql is installed but still mysql_config can't be find. This happens if python install can't find mysql_config in your system path, which mostly happens if you have done the installation via .dmg Mac Package or installed at some custom path. The easiest and documented way by MySqlDB is to change the site.cfg. Find the mysql_config which is probably in /usr/local/mysql/bin/ and change the variable namely mysql_config just like below and run the installation again. Don't forget to un-comment it by removing "#"
Change below line
to
depending upon the path in your system.
By the way I used python install after changing the site.cfg
sudo /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python setup.py install
So far, all solutions (Linux) require
sudo
or root rights to install . Here is a solution if you do not have root rights and withoutsudo
. (nosudo apt install ...
):dpkg -x libmysqlclient-dev_<version tag>.deb .
This will extract a folder calledusr
.Symlink
./usr/bin/mysql_config
to somewhere that is found on your$PATH
:ln -s
`pwd`
/usr/bin/mysql_config FOLDER_IN_YOUR_PATH
It should now be able to find
mysql_config
Tested on Ubuntu 18.04.
sudo apt-get build-dep python-mysqldb
will install all the dependencies to build the package from PIP/easy_install