I am trying to install MySQLdb for Python 2.6 as per these instructions:
http://www.tutorialspoint.com/python/python_database_access.htm
When I get to this step: $ python setup.py build
I get the error:
users-MacBook-Pro:MySQL-python-1.2.3 user$ sudo python setup.py build sh: mysql_config: command not found Traceback (most recent call last): File "setup.py", line 15, in metadata, options = get_config() File "/my_crawler/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config libs = mysql_config("libs_r") File "/my_crawler/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
I have MySQL installed and added to my bash
What am I doing wrong?
export PATH=$PATH:/usr/local/mysql/bin/
should fix the issue for you as the system is not able to find the mysql_config file.
While PlanetUnknown is on the right track with his/her answer, I hope this more explicit set of steps will prove useful:
The problem has to do with MySQLdb
not knowing where to look for the mysql_config
file.
So, let's find it for MySQLdb
and then put the location in its site.cfg
file so that it can find it from now on.
The OP is on a Mac, so open up the terminal and find the site.cfg
file:
sudo find / -name 'site.cfg'
Wait a few seconds and it should spit out the absolute path, we will vi
that file in a second. But first, find the the mysql_config
file:
sudo find / -name 'mysql_config'
Before editing the site.cfg
file, make sure you have the location of mysql_config
on your clipboard.
Once you have site.cfg
open in an editor, find the line specifying the path for mysql_config
. It is either pointing to the wrong path or just commented out all together. Either way, paste the correct path from your clipboard in place of the existing path.
You should now have a line in that file that reads something like:
mysql_config = /usr/local/path/to/mysql_config
Save the file.
It should be ready to run now, so give it another try.
It's not looking for 'mysql', it's looking for 'mysql_config'. Try running 'which mysql_config' from bash. It probably won't be found. That's why the build isn't finding it either. Try running 'locate mysql_config' and see if anything comes back. The path to this binary needs to be either in your shell's $PATH environment variable, or it needs to be explicitly in the setup.py file for the module assuming it's looking in some specific place for that file.
If you installed mysql from source in /usr/local, I believe the file will be found at /usr/local/mysql/bin/mysql_config
check the site.cfg in your mysqldb folder. It should be at the root.
Edit the site.cfg to the correct path of "mysql_config"
I found mine in "/usr/local/mysql/bin/"
Once done you should be able to run the build & install without any issues.
Remember you should be root or run all commands as "sudo"
精彩评论