mysql_config not found when installing mysqldb pyt

2019-01-01 12:07发布

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?

26条回答
低头抚发
2楼-- · 2019-01-01 12:23

The commands (mysql too) mPATH might be missing.

export PATH=$PATH:/usr/local/mysql/bin/

查看更多
心情的温度
3楼-- · 2019-01-01 12:24

mySQLdb is a python interface for mysql, but it is not mysql itself. And apparently mySQLdb needs the command 'mysql_config', so you need to install that first.

Can you confirm that you did or did not install mysql itself, by running "mysql" from the shell? That should give you a response other than "mysql: command not found".

Which linux distribution are you using? Mysql is pre-packaged for most linux distributions. For example, for debian / ubuntu, installing mysql is as easy as

sudo apt-get install mysql-server

mysql-config is in a different package, which can be installed from (again, assuming debian / ubuntu):

sudo apt-get install libmysqlclient-dev

if you are using mariadb, the drop in replacement for mysql, then run

sudo apt-get install libmariadbclient-dev
查看更多
梦寄多情
4楼-- · 2019-01-01 12:26

(Specific to mac) I have tried a lot many things, but these set of commands finally worked for me.

  1. brew install mysql # install mysql
  2. brew unlink mysql
  3. brew install mysql-connector-c
  4. export PATH=/usr/local/Cellar/mysql/8.0.11/bin:$PATH # update path and set the mysql bin folder to path
  5. sudo ln -s /usr/local/Cellar/mysql/8.0.11/lib/libmysqlclient.21.dylib /usr/local/Cellar/lib/libmysqlclient.21.dylib # create symlink
  6. pip install mysqlclient # install mysql-client finally
查看更多
无色无味的生活
5楼-- · 2019-01-01 12:27

The below worked for me on Ubuntu 12.04 LTS:

apt-get install libmysqlclient-dev python-dev

All though it worked, i still went ahead to do the below:

export PATH=$PATH:/usr/local/mysql/bin/
查看更多
呛了眼睛熬了心
6楼-- · 2019-01-01 12:27

Just type:

$ sudo apt-get install python-dev
$ venv/bin/pip install MySQL-python

This will solve this problems.

查看更多
人气声优
7楼-- · 2019-01-01 12:30

If you're on macOS and already installed mysql@5.7 via brew install:

  1. brew install mysql-connector-c
  2. brew unlink mysql@5.7
  3. brew link --overwrite --dry-run mysql@5.7 first, to see what symlinks are getting overwritten
  4. brew link --overwrite --force mysql@5.7 to actually overwrite mysql-related symlinks with mysql@5.7
  5. pip install mysqlclient
查看更多
登录 后发表回答