[英]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
但仍然收到此錯誤
這對我有用:
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
我首先解決了安裝 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
.dmg
,無需在這里復雜...which mysql_config
/usr/local/bin/mysql/bin/mysql_config
激活virtualenv
(如果適用)
pip install mysqlclient
可能還有其他方法仍然可以使用 Homebrew,但這是我找到的最直接的解決方案。
請注意, mysqlclient
GitHub README.md 還聲明需要 Python3 的 C-developer 標頭。 我假設mysql-connector-c
包括那些; 但是,如果遇到更多問題,您還可以安裝 Xcode Developer CI Tools 以備不時之需。
xcode-select --install
它們包括來自 Apple 的 C 編譯器和其他開發人員實用程序。 在這里閱讀更多。
在開發基於 django 的網站時遇到了這個問題,我需要設置網站以與 mysql 數據庫進行通信。 我沒有使用自制軟件進行任何安裝。
由於我在安裝了 Anaconda 的 MacOS 上進行開發,我發現 Anaconda 存在問題。 在不知道細節的情況下,我能夠使用conda install mysqlclient
希望也能幫助其他人解決這個問題。
對於特定程序上的 Python 2.7:
這解決了我在運行一個在 Python 2.7 和舊版本的 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,在嘗試執行pip3 install mysqlclient
以將 Django 連接到 MySQL 8.0.19 時遇到了類似的問題,但就我而言,它是在帶有 Python 3.8 的 macOS Catalina 10.15.5 上。 我也試過brew install mysql-connector-c
但它也給我帶來了很多麻煩。 以下是我設法讓它發揮作用的方法。
brew reinstall mysql
brew install mysql-client
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
參考資料:在 Mac OS X Sierra 上為 Django Python 安裝 mysqlclient
希望這能像今天對我一樣有效。 問候,阿爾弗雷多
這在 MacOS 10+ 上對我有用。 與其直接使用pip安裝mysqlclient,不如先使用這條命令
brew install mysql
如果您沒有 brew 的現有設置,請從它的主頁安裝 brew
然后運行
pip install mysqlclient
這應該有效,還要確保為您的項目設置了 virtualenv。 因為它是為每個項目單獨維護 venv 的良好做法之一。
對於那些在嘗試構建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
事實上,它類似於@yosbel 的回答。 但他的回答是針對類似 debian 的 linux 系統(例如 Ubuntu)。
我在 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.