Install MySQL-python runtime library in MAC_OS

New environment configuration

virtualenv --no-site-packages new_env

Install MySQL-python

pip install MySQL-python

Raise error

    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/8d/2c8f84vj48gg980_srg1ph200000gp/T/pip-install-gNeVyX/MySQL-python/setup.py", line 17, 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

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/8d/2c8f84vj48gg980_srg1ph200000gp/T/pip-install-gNeVyX/MySQL-python/

analysis

STEP1: Confirm the problem

Obviously, the error is seen here because there is no mysql_config command. Run the command here to check whether mysql_config is in the system.

which mysql_config

System returns

mysql_config not found

The instruction does not exist.


Go to mysql official website to query mysql_config to understand the usefulness of the mysql_config command tool.

tip1: 编译MySQL客户端并将其连接到MySQL
tip2: 它是一个shell脚本

I got mysql_config here, which is a SHELL script used to compile MySQL client and connect it to MySQL. This can basically explain why MySQL-python needs mysql_config script.
In short, MySQL-python is an implementation of using Python and MySQL builds a connection and provides a client to call the API to python program developers.

STEP2: Conversion problem

Because there is no way to install mysql_config directly, because MySQL does not officially provide download capabilities.

安装mysql_config工具
安装带有mysql_config工具的工具
STEP3: Confirm the tool with mysql_config tool

Among the tools that can be installed in brew , there are several commonly used ones with the mysql_config tool.

Tool name Installation method
mysql-client brew install mysql-client
mysql brew install mysql

implementation plan

The mysql-client is selected here, and mysql-client is also recommended. mysql-client is a tool specifically used to build and connect to MySQL. The corresponding extension and development dependencies are relatively complete.

brew install mysql-client

Return after success

==> Downloading https://homebrew.bintray.com/bottles/mysql-client-5.7.23.mojave.bottle.tar.gz
Already downloaded: /Users/zhiping.li/Library/Caches/Homebrew/downloads/4aac41a5c1a9775a2206e2e4a0b2f298aa3170c480d37306655a131d5882998f--mysql-client-5.7.23.mojave.bottle.tar.gz
==> Pouring mysql-client-5.7.23.mojave.bottle.tar.gz
==> Caveats
mysql-client is keg-only, which means it was not symlinked into /usr/local,
because conflicts with mysql.

If you need to have mysql-client first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc

For compilers to find mysql-client you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql-client/include"

For pkg-config to find mysql-client you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/mysql-client/lib/pkgconfig"

==> Summary
?  /usr/local/Cellar/mysql-client/5.7.23: 232 files, 80.5MB==> Downloading https://homebrew.bintray.com/bottles/mysql-client-5.7.23.mojave.bottle.tar.gz
Already downloaded: /Users/zhiping.li/Library/Caches/Homebrew/downloads/4aac41a5c1a9775a2206e2e4a0b2f298aa3170c480d37306655a131d5882998f--mysql-client-5.7.23.mojave.bottle.tar.gz
==> Pouring mysql-client-5.7.23.mojave.bottle.tar.gz
==> Caveats
mysql-client is keg-only, which means it was not symlinked into /usr/local,
because conflicts with mysql.

If you need to have mysql-client first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc

For compilers to find mysql-client you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql-client/include"

For pkg-config to find mysql-client you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/mysql-client/lib/pkgconfig"

==> Summary
?  /usr/local/Cellar/mysql-client/5.7.23: 232 files, 80.5MB

Configure environment variables and compiler dependencies according to the returned instructions.

# 配置环境变量
export PATH="/usr/local/opt/mysql-client/bin:$PATH"

# 配置编译器依赖
export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
export CPPFLAGS="-I/usr/local/opt/mysql-client/include"

After running the above instructions, pip can find the corresponding mysql_config tool when installing MySQL-python and compiling and generating the client.

pip install MySQL-python

Generally it will be installed successfully

Collecting MySQL-python
Installing collected packages: MySQL-python
Successfully installed MySQL-python-1.2.5

TIPS

Sometimes, you may not be able to compile the program due to dependency library issues such as xcode, but it has nothing to do with mysql_config. At this time, you need to solve the problem of installing or updating xcode dependencies. You can refer to some mature articles.

Guess you like

Origin blog.csdn.net/m0_37964621/article/details/86737030