Nueva configuración de entorno
virtualenv --no-site-packages new_env
Instalar MySQL-python
pip install MySQL-python
Aumento de 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/
análisis
PASO 1: Confirme el problema
Obviamente, el error se ve aquí porque no hay un comando mysql_config. Ejecute el comando aquí para verificar si mysql_config está en el sistema.
which mysql_config
Devoluciones del sistema
mysql_config not found
La instrucción no existe.
Vaya al sitio web oficial de mysql para consultar mysql_config y comprender la utilidad de la herramienta de comando mysql_config.
tip1: 编译MySQL客户端并将其连接到MySQL
tip2: 它是一个shell脚本
Obtuve mysql_config aquí, que es un script SHELL que se usa para compilar el cliente MySQL y conectarlo a MySQL. Esto básicamente puede explicar por qué MySQL-python necesita el script mysql_config.
En resumen, MySQL-python es una implementación del uso de Python y MySQL crea una conexión y proporciona un cliente para llamar a la API a los desarrolladores de programas de Python.
PASO 2: Problema de conversión
Porque no hay forma de instalar mysql_config directamente, porque MySQL no proporciona oficialmente capacidades de descarga.
PASO 3: Confirme la herramienta con la herramienta mysql_config
Entre las herramientas que se pueden instalar en brew , hay varias de uso común con la herramienta mysql_config.
Nombre de la herramienta | Metodo de instalacion |
---|---|
cliente mysql | brew instalar mysql-client |
mysql | brew instalar mysql |
plan de IMPLEMENTACION
Aquí se selecciona mysql-client, y también se recomienda mysql-client. Mysql-client es una herramienta que se usa específicamente para construir y conectarse a MySQL. Las dependencias de extensión y desarrollo correspondientes son relativamente completas.
brew install mysql-client
Regreso después del éxito
==> 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 las variables de entorno y las dependencias del compilador de acuerdo con las instrucciones devueltas.
# 配置环境变量
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"
Después de ejecutar las instrucciones anteriores, pip puede encontrar la herramienta mysql_config correspondiente al instalar MySQL-python y compilar y generar el cliente.
pip install MySQL-python
Generalmente se instalará con éxito
Collecting MySQL-python
Installing collected packages: MySQL-python
Successfully installed MySQL-python-1.2.5
CONSEJOS
A veces, es posible que no pueda compilar el programa debido a problemas de la biblioteca de dependencias como xcode, pero no tiene nada que ver con mysql_config. En este momento, debe resolver el problema de instalar o actualizar las dependencias de xcode. Puede consultar algunos artículos maduros.