[英]python setup.py egg_info mysqlclient
Trying to install mysqlclient using pip3 on Python 3.6.0尝试在 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/
Already did已经做了
brew install mysql-connector-c
But still getting this error但仍然收到此错误
This worked for me:这对我有用:
brew install mysql-connector-c
edit mysql_config
(locate it: which mysql_config
)编辑
mysql_config
(找到它: which mysql_config
)
correct this in mysql_config:在 mysql_config 中更正此问题:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
It shoud be:它应该是:
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
brew info openssl
pip3 install mysqlclient
pip3 install mysqlclient
I resolved this installing libmysqlclient-dev first:我首先解决了安装 libmysqlclient-dev 的问题:
sudo apt-get install libmysqlclient-dev
Hope it works for you.希望对你有效。
After extensive troubleshooting, I found that the brew install mysql-connector-c
just does not work.经过广泛的故障排除后,我发现
brew install mysql-connector-c
根本不起作用。
The problem stems from the system not being able to identify that mysql_config
is installed (which is what mysql-connector-c
essentially does).问题源于系统无法识别安装了
mysql_config
(这是mysql-connector-c
本质上所做的)。 Homebrew's method (open for argument) of installing the mysql-connector-c
in its /Cellar/
and creating a symlink to the /usr/local/bin/
directory seems to be causing problems as Python tries to follow the symlink. Homebrew 在其
/Cellar/
中安装mysql-connector-c
并创建到/usr/local/bin/
目录的符号链接的方法(公开讨论)似乎会导致问题,因为 Python 试图遵循符号链接。
To resolve the issue I performed the following:为了解决这个问题,我执行了以下操作:
brew uninstall mysql-connector-c
.dmg
, no need to be complicated here....dmg
,无需在这里复杂...which mysql_config
/usr/local/bin/mysql/bin/mysql_config
/usr/local/bin/mysql/bin/mysql_config
activate virtualenv
(if applicable)激活
virtualenv
(如果适用)
pip install mysqlclient
There may be other ways to still use Homebrew, but this was the most straightforward solution I found.可能还有其他方法仍然可以使用 Homebrew,但这是我找到的最直接的解决方案。
Note that the mysqlclient
GitHub README.md also states that the C-developer headers for Python3 are needed.请注意,
mysqlclient
GitHub README.md 还声明需要 Python3 的 C-developer 标头。 I assume that mysql-connector-c
includes those;我假设
mysql-connector-c
包括那些; however, should you run into more issues, you might also install the Xcode Developer CI Tools for good measure.但是,如果遇到更多问题,您还可以安装 Xcode Developer CI Tools 以备不时之需。
xcode-select --install
They include the C compiler and other developer utilities from Apple.它们包括来自 Apple 的 C 编译器和其他开发人员实用程序。 Read more here .
在这里阅读更多。
Came across this while developing a django-based website, and I needed to set up the website to communicate with a mysql database.在开发基于 django 的网站时遇到了这个问题,我需要设置网站以与 mysql 数据库进行通信。 I've not used homebrew to do any of my installations.
我没有使用自制软件进行任何安装。
Since I'm doing the development on a MacOS with Anaconda installed, I discovered that there was an issue with Anaconda.由于我在安装了 Anaconda 的 MacOS 上进行开发,我发现 Anaconda 存在问题。 Without knowing the details, I was able to install mysqlclient with
conda install mysqlclient
在不知道细节的情况下,我能够使用
conda install mysqlclient
Hope that helps someone else with this problem as well.希望也能帮助其他人解决这个问题。
For Python 2.7 on specific programs:对于特定程序上的 Python 2.7:
This solved all issues I was having running a program that ran on Python 2.7 on and older version of MySql这解决了我在运行一个在 Python 2.7 和旧版本的 MySql 上运行的程序时遇到的所有问题
Other options didn't work for me, but this worked for me:其他选项对我不起作用,但这对我有用:
For Python3:对于 Python3:
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip3 install mysqlclient
For Python2:对于 Python2:
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip2 install mysqlclient
or要么
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install mysqlclient
Personally I recommend using pymysql
instead of using mysqlclient
.我个人建议使用
pymysql
而不是使用mysqlclient
。 You can install pymysql
with:您可以使用以下命令安装
pymysql
:
pip install pymysql
And you might edit your SQLAlchemy URL to:您可以将 SQLAlchemy URL 编辑为:
mysql+pymysql://username:passwd@hostname/database
I'm just getting started with python and had similar problems when trying to do pip3 install mysqlclient
to connect Django to MySQL 8.0.19 but on my case it is on a macOS Catalina 10.15.5 with Python 3.8.我刚刚开始使用 python,在尝试执行
pip3 install mysqlclient
以将 Django 连接到 MySQL 8.0.19 时遇到了类似的问题,但就我而言,它是在带有 Python 3.8 的 macOS Catalina 10.15.5 上。 I also tried brew install mysql-connector-c
but it also gave me a lot of trouble.我也试过
brew install mysql-connector-c
但它也给我带来了很多麻烦。 Here's how I manage to make it work.以下是我设法让它发挥作用的方法。
brew reinstall mysql
brew install mysql-client
mysql-client
I got the following messages in the terminal which I just followed and got all to work.mysql-client
后,我在终端中收到了以下消息,我只是按照这些消息进行操作并开始工作。echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
export CPPFLAGS="-I/usr/local/opt/mysql-client/include"
pip3 install mysqlclient
References: Install mysqlclient for Django Python on Mac OS X Sierra参考资料:在 Mac OS X Sierra 上为 Django Python 安装 mysqlclient
Hope this works as it did for me today.希望这能像今天对我一样有效。 Regards, Alfredo
问候,阿尔弗雷多
This worked for me on MacOS 10+.这在 MacOS 10+ 上对我有用。 Rather than directly installing mysqlclient using pip, use this command first
与其直接使用pip安装mysqlclient,不如先使用这条命令
brew install mysql
If you do not have an existing setup for brew, then install brew from it's homepage如果您没有 brew 的现有设置,请从它的主页安装 brew
Then run然后运行
pip install mysqlclient
This should work, Also ensure you have a virtualenv set up for your projects.这应该有效,还要确保为您的项目设置了 virtualenv。 as it is among good practices to maintain venv's for each project seperately.
因为它是为每个项目单独维护 venv 的良好做法之一。
For those who have similar error while trying to build python:<version>-alpine
docker image, here is the solution:对于那些在尝试构建
python:<version>-alpine
docker 图像时遇到类似错误的人,这里是解决方案:
FROM python:3.10-alpine
<...>
RUN apk update \
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add --no-cache mariadb-dev
RUN python -m pip install mysqlclient==2.1.1
If fact, it is similar to @yosbel's answer .事实上,它类似于@yosbel 的回答。 But his answer is for debian-like linux systems (eg Ubuntu).
但他的回答是针对类似 debian 的 linux 系统(例如 Ubuntu)。
Error message I got with alpine image is below:我在 alpine 图像中收到的错误消息如下:
Collecting mysqlclient==2.1.1
Downloading mysqlclient-2.1.1.tar.gz (88 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 88.1/88.1 kB 6.8 MB/s eta 0:00:00
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'error'
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
<...>
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.