pip 安装 MySQL-python
pip install MySQL-python
我正在尝试在 Mac OS 上为 Python 安装 MySQLdb。
当我将 pip install MySQL-python
shell returns 数字化为:
Collecting MySQL-python
Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/9h/2lp9kx993ygbrfk1lxr0sz500000gq/T/pip-install-7xyyBe/MySQL-python/setup.py", line 17, in
metadata, options = get_config()
File "setup_posix.py", line 53, in get_config
libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
File "setup_posix.py", line 8, in dequote
if s[0] in "\"'" and s[0] == s[-1]:
IndexError: string index out of range
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/9h/2lp9kx993ygbrfk1lxr0sz500000gq/T/pip-install-7xyyBe/MySQL-python/
我能做什么?我到处搜索,但找不到答案。
(我安装了 Python 2.7)
我修正了错误。如果有人遇到此错误,请按照以下步骤操作:
首先安装mysql连接器
brew install mysql-connector-c
- 您必须修改 mysql_config 中的行(这是一个别名)
vim /usr/local/bin/mysql_config
(我真心考虑用文件编辑器打开mysql_config,你可以找到
确切的文件夹在这里)
/usr/local/Cellar/mysql-connector-c/6.1.11/bin/
- 替换这些行。
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
应该是:
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
- 设置环境变量
brew info openssl
它会告诉需要什么
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
For pkg-config to find this software you may need to set:
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
- 然后就可以安装了MySQL
pip install MySQL-python
- 您可以测试是否安装了 MySQL:
python -c "import MySQLdb"
希望这对你也有用!
我正在尝试在 Mac OS 上为 Python 安装 MySQLdb。
当我将 pip install MySQL-python
shell returns 数字化为:
Collecting MySQL-python Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 1, in File "/private/var/folders/9h/2lp9kx993ygbrfk1lxr0sz500000gq/T/pip-install-7xyyBe/MySQL-python/setup.py", line 17, in metadata, options = get_config() File "setup_posix.py", line 53, in get_config libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ] File "setup_posix.py", line 8, in dequote if s[0] in "\"'" and s[0] == s[-1]: IndexError: string index out of range ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/9h/2lp9kx993ygbrfk1lxr0sz500000gq/T/pip-install-7xyyBe/MySQL-python/
我能做什么?我到处搜索,但找不到答案。 (我安装了 Python 2.7)
我修正了错误。如果有人遇到此错误,请按照以下步骤操作:
首先安装mysql连接器
brew install mysql-connector-c
- 您必须修改 mysql_config 中的行(这是一个别名)
vim /usr/local/bin/mysql_config
(我真心考虑用文件编辑器打开mysql_config,你可以找到 确切的文件夹在这里)
/usr/local/Cellar/mysql-connector-c/6.1.11/bin/
- 替换这些行。
# Create options libs="-L$pkglibdir" libs="$libs -l "
应该是:
# Create options libs="-L$pkglibdir" libs="$libs -lmysqlclient -lssl -lcrypto"
- 设置环境变量
brew info openssl
它会告诉需要什么
For compilers to find this software you may need to set: LDFLAGS: -L/usr/local/opt/openssl/lib CPPFLAGS: -I/usr/local/opt/openssl/include For pkg-config to find this software you may need to set: PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
- 然后就可以安装了MySQL
pip install MySQL-python
- 您可以测试是否安装了 MySQL:
python -c "import MySQLdb"
希望这对你也有用!