python setup.py egg_info mysql客户端
python setup.py egg_info mysqlclient
正在尝试在 Python 3.6.0
上使用 pip3 安装 mysqlclient
$ pip3 install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.10.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 54, in get_config
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 54, in <listcomp>
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 12, 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/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/
已经做了
brew install mysql-connector-c
但仍然出现此错误
我首先解决了安装 libmysqlclient-dev 的问题:
sudo apt-get install libmysqlclient-dev
希望对你有用。
经过 广泛 故障排除后,我发现 brew install mysql-connector-c
根本不起作用。
问题源于系统无法识别 mysql_config
已安装(mysql-connector-c
本质上就是这样做的)。 Homebrew 在其 /Cellar/
中安装 mysql-connector-c
并创建到 /usr/local/bin/
目录的符号链接的方法(公开讨论)似乎导致了问题,因为 Python 试图遵循符号链接.
为了解决这个问题,我执行了以下操作:
brew uninstall mysql-connector-c
- download/install MacOS X MySQL Connector/C 来自 Oracle 的 MySQL 站点
- 注意:下载
.dmg
即可,这里不用复杂...
- 重新启动 MacOS 终端(或 iTerm2)以取得良好效果
which mysql_config
- 你应该看到正确的路径
/usr/local/bin/mysql/bin/mysql_config
激活virtualenv
(如果适用)
pip install mysqlclient
可能还有其他方法可以继续使用 Homebrew,但这是我找到的最直接的解决方案。
请注意 mysqlclient
GitHub README.md 还声明 C-developer headers 需要 Python3。我假设 mysql-connector-c
包括那些;但是,如果您 运行 遇到更多问题,您还可以安装 Xcode 开发人员 CI 工具作为很好的衡量标准。
xcode-select --install
它们包括来自 Apple 的 C 编译器和其他开发人员实用程序。阅读更多 here.
这对我有用:
brew install mysql-connector-c
编辑mysql_config
(定位:which mysql_config
)
在 mysql_config 中更正:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
应该是:
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
brew info openssl
- 最后是
pip3 install mysqlclient
在开发基于 django 的网站时遇到了这个问题,我需要设置该网站以与 mysql 数据库通信。我没有使用自制软件进行任何安装。
由于我在安装了 Anaconda 的 MacOS 上进行开发,我发现 Anaconda 存在问题。在不知道细节的情况下,我能够使用 conda install mysqlclient
安装 mysql 客户端
希望也能帮助其他人解决这个问题。
其他选项对我不起作用,但这对我有用:
对于Python3:
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip3 install mysqlclient
对于Python2:
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip2 install mysqlclient
或
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install mysqlclient
我个人建议使用 pymysql
而不是 mysqlclient
。您可以通过以下方式安装 pymysql
:
pip install pymysql
并且您可以将 SQLAlchemy URL 编辑为:
mysql+pymysql://username:passwd@hostname/database
对于 Python 2.7 特定程序:
- sudo chown -R $USER /Library/Python/2.7
- brew 安装mysql@5.7
- brew 安装mysql-connector-c
- brew link --overwrite mysql@5.7
- echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
- sed -i -e 's/libs="$libs -l "/libs="$libs -lmysqlclient -lssl -lcrypto"/g' /usr/local/bin/mysql_config
- pip 安装MySql-python
这解决了我遇到的所有问题 运行 运行 在 Python 2.7 和旧版本 MySql
上的程序
我刚开始使用 python,在尝试 pip3 install mysqlclient
将 Django 连接到 MySQL 8.0.19 时遇到了类似的问题,但就我而言,它在macOS Catalina 10.15.5 与 Python 3.8。我也试过 brew install mysql-connector-c
但是也给我带来了很多麻烦。这是我设法让它发挥作用的方法。
brew reinstall mysql
brew install mysql-client
- 注意:安装
mysql-client
后,我在终端中收到了以下消息,我刚刚按照这些消息进行操作,一切正常。
- mysql-client 是 keg-only,这意味着它没有符号链接到 /usr/local,因为它与 mysql(包含客户端库)冲突。如果您需要 mysql-client 在您的 PATH 运行:
中首先
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
- 为了让编译器找到 mysql-client,您可能需要设置:
export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
export CPPFLAGS="-I/usr/local/opt/mysql-client/include"
- 然后我再次尝试安装 mysql客户端,它成功了。我还在 python .venv 环境中尝试过它,它也可以使用:
pip3 install mysqlclient
参考文献:Install mysqlclient for Django Python on Mac OS X Sierra
希望这对我今天一样有效。
问候,
阿尔弗雷多
这对我适用于 MacOS 10+。
与其直接用pip安装mysqlclient,不如先用这个命令
brew install mysql
如果您没有现有的 brew 安装程序,请从它的主页安装 brew
然后运行
pip install mysqlclient
这应该行得通!还要确保为项目设置了 virtualenv,因为为每个项目单独维护 venv 是一种很好的做法。
正在尝试在 Python 3.6.0
上使用 pip3 安装 mysqlclient$ pip3 install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.10.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 54, in get_config
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 54, in <listcomp>
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 12, 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/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/
已经做了
brew install mysql-connector-c
但仍然出现此错误
我首先解决了安装 libmysqlclient-dev 的问题:
sudo apt-get install libmysqlclient-dev
希望对你有用。
经过 广泛 故障排除后,我发现 brew install mysql-connector-c
根本不起作用。
问题源于系统无法识别 mysql_config
已安装(mysql-connector-c
本质上就是这样做的)。 Homebrew 在其 /Cellar/
中安装 mysql-connector-c
并创建到 /usr/local/bin/
目录的符号链接的方法(公开讨论)似乎导致了问题,因为 Python 试图遵循符号链接.
为了解决这个问题,我执行了以下操作:
brew uninstall mysql-connector-c
- download/install MacOS X MySQL Connector/C 来自 Oracle 的 MySQL 站点
- 注意:下载
.dmg
即可,这里不用复杂...
- 注意:下载
- 重新启动 MacOS 终端(或 iTerm2)以取得良好效果
which mysql_config
- 你应该看到正确的路径
/usr/local/bin/mysql/bin/mysql_config
- 你应该看到正确的路径
激活
virtualenv
(如果适用)pip install mysqlclient
可能还有其他方法可以继续使用 Homebrew,但这是我找到的最直接的解决方案。
请注意 mysqlclient
GitHub README.md 还声明 C-developer headers 需要 Python3。我假设 mysql-connector-c
包括那些;但是,如果您 运行 遇到更多问题,您还可以安装 Xcode 开发人员 CI 工具作为很好的衡量标准。
xcode-select --install
它们包括来自 Apple 的 C 编译器和其他开发人员实用程序。阅读更多 here.
这对我有用:
brew install mysql-connector-c
编辑
mysql_config
(定位:which mysql_config
)
在 mysql_config 中更正:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
应该是:
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
brew info openssl
- 最后是
pip3 install mysqlclient
在开发基于 django 的网站时遇到了这个问题,我需要设置该网站以与 mysql 数据库通信。我没有使用自制软件进行任何安装。
由于我在安装了 Anaconda 的 MacOS 上进行开发,我发现 Anaconda 存在问题。在不知道细节的情况下,我能够使用 conda install mysqlclient
希望也能帮助其他人解决这个问题。
其他选项对我不起作用,但这对我有用:
对于Python3:
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip3 install mysqlclient
对于Python2:
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip2 install mysqlclient
或
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install mysqlclient
我个人建议使用 pymysql
而不是 mysqlclient
。您可以通过以下方式安装 pymysql
:
pip install pymysql
并且您可以将 SQLAlchemy URL 编辑为:
mysql+pymysql://username:passwd@hostname/database
对于 Python 2.7 特定程序:
- sudo chown -R $USER /Library/Python/2.7
- brew 安装mysql@5.7
- brew 安装mysql-connector-c
- brew link --overwrite mysql@5.7
- echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
- sed -i -e 's/libs="$libs -l "/libs="$libs -lmysqlclient -lssl -lcrypto"/g' /usr/local/bin/mysql_config
- pip 安装MySql-python
这解决了我遇到的所有问题 运行 运行 在 Python 2.7 和旧版本 MySql
上的程序我刚开始使用 python,在尝试 pip3 install mysqlclient
将 Django 连接到 MySQL 8.0.19 时遇到了类似的问题,但就我而言,它在macOS Catalina 10.15.5 与 Python 3.8。我也试过 brew install mysql-connector-c
但是也给我带来了很多麻烦。这是我设法让它发挥作用的方法。
brew reinstall mysql
brew install mysql-client
- 注意:安装
mysql-client
后,我在终端中收到了以下消息,我刚刚按照这些消息进行操作,一切正常。 - mysql-client 是 keg-only,这意味着它没有符号链接到 /usr/local,因为它与 mysql(包含客户端库)冲突。如果您需要 mysql-client 在您的 PATH 运行: 中首先
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
- 为了让编译器找到 mysql-client,您可能需要设置:
export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
export CPPFLAGS="-I/usr/local/opt/mysql-client/include"
- 然后我再次尝试安装 mysql客户端,它成功了。我还在 python .venv 环境中尝试过它,它也可以使用:
pip3 install mysqlclient
参考文献:Install mysqlclient for Django Python on Mac OS X Sierra
希望这对我今天一样有效。 问候, 阿尔弗雷多
这对我适用于 MacOS 10+。 与其直接用pip安装mysqlclient,不如先用这个命令
brew install mysql
如果您没有现有的 brew 安装程序,请从它的主页安装 brew
然后运行
pip install mysqlclient
这应该行得通!还要确保为项目设置了 virtualenv,因为为每个项目单独维护 venv 是一种很好的做法。