Macos m系列芯片環境下python3安裝mysqlclient系列問題

最近學習python3,在安裝mysqlclient的時候遇到了一些問題,直接使用哦pip install mysqlclient 直接報錯了,記錄一下解決方案。

環境信息
設備:Macbook Pro m1
系統:macos Sequoia 15.3.2
最終成功的python版本:Python3.13.3
pip版本:25.0.1
最終系統環境下mysqlclient版本:2.2.7 -> 對應mysql-client: 8.0.42

直接執行命令安裝: pip3 install mysqlclient,報錯信息:

Collecting mysqlclientUsing cached mysqlclient-2.2.7.tar.gz (91 kB)Installing build dependencies ... doneGetting requirements to build wheel ... errorerror: subprocess-exited-with-error× Getting requirements to build wheel did not run successfully.│ exit code: 1╰─> [35 lines of output]/bin/sh: pkg-config: command not found/bin/sh: pkg-config: command not found/bin/sh: pkg-config: command not found/bin/sh: pkg-config: command not foundTrying pkg-config --exists mysqlclientCommand 'pkg-config --exists mysqlclient' returned non-zero exit status 127.Trying pkg-config --exists mariadbCommand 'pkg-config --exists mariadb' returned non-zero exit status 127.Trying pkg-config --exists libmariadbCommand 'pkg-config --exists libmariadb' returned non-zero exit status 127.Trying pkg-config --exists perconaserverclientCommand 'pkg-config --exists perconaserverclient' returned non-zero exit status 127.Traceback (most recent call last):File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>main()~~~~^^File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in mainjson_out["return_val"] = hook(**hook_input["kwargs"])~~~~^^^^^^^^^^^^^^^^^^^^^^^^File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 143, in get_requires_for_build_wheelreturn hook(config_settings)File "/private/var/folders/pg/lcz_0brx7dl64hcxtkjtrn1c0000gp/T/pip-build-env-lqq7jo65/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 331, in get_requires_for_build_wheelreturn self._get_build_requires(config_settings, requirements=[])~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "/private/var/folders/pg/lcz_0brx7dl64hcxtkjtrn1c0000gp/T/pip-build-env-lqq7jo65/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 301, in _get_build_requiresself.run_setup()~~~~~~~~~~~~~~^^File "/private/var/folders/pg/lcz_0brx7dl64hcxtkjtrn1c0000gp/T/pip-build-env-lqq7jo65/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 317, in run_setupexec(code, locals())~~~~^^^^^^^^^^^^^^^^File "<string>", line 156, in <module>File "<string>", line 49, in get_config_posixFile "<string>", line 28, in find_package_nameException: Can not find valid pkg-config name.Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually[end of output]note: This error originates from a subprocess, and is likely not a problem with pip.

看錯誤信息是少了pkg-config
執行命令:brew install pkg-config,也報錯!!!

fatal: not in a git directory
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
Running `brew update --auto-update`...
Warning: You are using macOS 15.
We do not provide support for this pre-release version.
It is expected behaviour that some formulae will fail to build in this pre-release version.
It is expected behaviour that Homebrew will be buggy and slow.
Do not create any issues about this on Homebrew's GitHub repositories.
Do not create any issues even if you think this message is unrelated.
Any opened issues will be immediately closed without response.
Do not ask for help from MacHomebrew on Twitter.
You may ask for help in Homebrew's discussions but are unlikely to receive a response.
Try to figure out the problem yourself and submit a fix as a pull request.
We will review it but may or may not accept it.==> Fetching pkg-config
==> Downloading https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar
######################################################################## 100.0%
==> ./configure --prefix=/opt/homebrew/Cellar/pkg-config/0.29.2_3 --disable-host
==> make
Last 15 lines from /Users/nankexiansheng/Library/Logs/Homebrew/pkg-config/02.make:
gatomic.c:464:10: error: incompatible integer to pointer conversion passing 'gsize' (aka 'unsigned long') to parameter of type 'gpointer' (aka 'void *') [-Wint-conversion]464 |   return g_atomic_pointer_xor ((volatile gpointer *) atomic, val);|          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./gatomic.h:191:45: note: expanded from macro 'g_atomic_pointer_xor'191 |     (gsize) __sync_fetch_and_xor ((atomic), (val));                          \|                                             ^~~~~
4 errors generated.
make[6]: *** [libglib_2_0_la-gatomic.lo] Error 1
make[6]: *** Waiting for unfinished jobs....
make[5]: *** [all-recursive] Error 1
make[4]: *** [all] Error 2
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2Do not report this issue to Homebrew/brew or Homebrew/core!Error: You are using macOS 15.
We do not provide support for this pre-release version.
It is expected behaviour that some formulae will fail to build in this pre-release version.
It is expected behaviour that Homebrew will be buggy and slow.
Do not create any issues about this on Homebrew's GitHub repositories.
Do not create any issues even if you think this message is unrelated.
Any opened issues will be immediately closed without response.
Do not ask for help from MacHomebrew on Twitter.
You may ask for help in Homebrew's discussions but are unlikely to receive a response.
Try to figure out the problem yourself and submit a fix as a pull request.
We will review it but may or may not accept it.

解決方法:
mysqlclient安裝
可以參考mysqlclient文檔
首選確保你的macos已經安裝配置好了brew,以及配置了國內源。

# 安裝pkg-config
brew install pkg-config
注意:如果這里報錯,先執行下brew install mysql;再執行brew install pkg-config命令
# 安裝 mysql-client
brew install mysql-client@8.0
# 添加環境變量 在 ~/.zshrc 中添加下面這行
export PKG_CONFIG_PATH="$(brew --prefix)/opt/mysql-client@8.0/lib/pkgconfig"保存后 source ~/.zshrc 刷新環境變量通過 printenv 可以查看確認當前環境變量

接下來可以正常安裝mysqlclient,這里我安裝的是mysqlclient 2.2.7版本

注意??:2.0.0 以上版本需要python3.8及以上才能兼容

pip3 install mysqlclient

如果正常安裝完成,沒有報錯,進入當前python運行環境測試
在這里插入圖片描述
如果能正常引入MySQLdb而沒有報錯,那么基本上算上順利完成了。可以嘗試在虛擬環境安裝完依賴啟動項目試試

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/77651.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/77651.shtml
英文地址,請注明出處:http://en.pswp.cn/web/77651.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

微信小程序-van-uploader的preview-size

preview-size支持數組格式 修改前修改后1、升級微信小程序里面的van版本:2、 重新構建npm3、重啟微信開發工具 修改前 引用van組件的上傳文件&#xff0c;設置預覽圖尺寸&#xff0c;剛開始設置的是preview-size“140”&#xff0c;出來的效果就是一個正方形。 修改后 1、升級…

2. 第一個網頁:前端基礎入門

第一個網頁&#xff1a;前端基礎入門 一、網頁文件基礎認知 1. 文件擴展名 .htm 或 .html 均為網頁文件后綴&#xff0c;二者功能完全一致擴展名隱藏方法 系統設置 → 文件夾選項 → 查看 → 取消勾選「隱藏已知文件類型的擴展名」 二、前端發展簡史 1. 瀏覽器戰爭與標準混…

云原生--核心組件-容器篇-7-Docker私有鏡像倉庫--Harbor

1、Harbor的定義與核心作用 定義&#xff1a; Harbor是由VMware開源的企業級容器鏡像倉庫系統&#xff0c;后捐贈給 CNCF (Cloud Native Computing Foundation)。它基于Docker Registry擴展了企業級功能&#xff0c;用于存儲、分發和管理容器鏡像&#xff08;如Docker、OCI標準…

Java項目與技術棧場景題深度解析

Java項目與技術棧場景題深度解析 在互聯網大廠Java求職者的面試中&#xff0c;經常會被問到關于Java項目或技術棧的場景題。本文通過一個故事場景來展示這些問題的實際解決方案。 第一輪提問 面試官&#xff1a;馬架構&#xff0c;歡迎來到我們公司的面試現場。請問您對Java…

SpringMVC 靜態資源處理 mvc:default-servlet-handler

我們先來看看效果,當我把這一行注釋掉的時候&#xff1a; 我們來看看頁面&#xff1a; 現在我把注釋去掉&#xff1a; 、 可以看到的是&#xff0c;這個時候又可以訪問了 那么我們就可以想&#xff0c;這個 <mvc:default-servlet-handler />它控制著我們頁面的訪問…

【leetcode】最長公共子路徑問題

滾動hash 滾動哈希&#xff08;rolling hash&#xff09;也叫 Rabin-Karp 字符串哈希算法&#xff0c;它是將某個字符串看成某個進制下的整數&#xff0c;并將其對應的十進制整數作為hash值。 滾動hash算法的推導 假設有一個長度為n的數組a[0],a[1],a[2],…a[n-1]&#xff0…

【Linux網絡】:套接字之UDP

一、UDP和TCP協議 TCP &#xff08;Transmission Control Protocol 傳輸控制協議&#xff09;的特點&#xff1a; 傳輸層協議有連接&#xff08;在正式通信前要先建立連接&#xff09;可靠傳輸&#xff08;在內部幫我們做可靠傳輸工作&#xff09;面向字節流 UDP &#xff08;U…

React19 useOptimistic 用法

用法 樂觀更新 發起異步請求時&#xff0c;先假設請求會成功立即更新 UI 給用戶反饋若請求最終失敗&#xff0c;再將 UI 恢復到之前的狀態 const [optimisticState, addOptimistic] useOptimistic(state, updateFn) 參數 state&#xff1a;實際值&#xff0c;可以是 useSta…

Deepseek-v3+cline+vscode java自動化編程

1、Deepseek DeepSeek 充值后&#xff0c;創建apikey 2、vscode Visual Studio Code - Code Editing. Redefined 3、下載插件cline 4、配置deepeseek-v3 的密鑰到cline 5、不可用 在開始的幾次調用能正常使用起來&#xff0c;用了幾次后&#xff0c;不能使用了&#xff0c;請求…

數據分析案例:環境數據分析

目錄 數據分析案例&#xff1a;環境數據分析1. 項目背景2. 數據加載與預處理2.1 數據說明2.2 讀取與清洗 3. 探索性數據分析&#xff08;EDA&#xff09;3.1 時序趨勢3.2 日內變化3.3 氣象與污染物相關性 4. 特征工程4.1 時間特征4.2 滯后與滾動統計4.3 目標變量 5. 模型構建與…

網絡原理 - 8

目錄 補充 網絡層 IP 協議 基本概念&#xff1a; 協議頭格式 地址管理 如何解決 IP 地址不夠用呢&#xff1f;&#xff1f;&#xff1f; 1. 動態分配 IP 地址&#xff1a; 2. NAT 機制&#xff08;網絡地址映射&#xff09; 3. IPv6 網段劃分 一些特殊的 IP 地址 …

向量檢索新選擇:FastGPT + OceanBase,快速構建RAG

隨著人工智能的快速發展&#xff0c;RAG&#xff08;Retrieval-Augmented Generation&#xff0c;檢索增強生成&#xff09;技術日益受到關注。向量數據庫作為 RAG 系統的核心基礎設施&#xff0c;堪稱 RAG 的“記憶中樞”&#xff0c;其性能直接關系到大模型生成內容的精準度與…

dify對接飛書云文檔,并且將圖片傳入飛書文檔

前面講了如何讓dify展示圖片&#xff0c;但是如果想讓智能體回答的帶圖片的內容生成個文檔該怎么弄呢&#xff1f;今天來實踐一下。 dify工具帶的有飛書云文檔&#xff0c;正好&#xff0c;咱們就利用飛書云文檔。 1、首先配置飛書云文檔的key跟secret 注意要開頭左側的權限&a…

Linux系統之設置開機啟動運行桌面環境

Linux 開機運行級別介紹與 Ubuntu 桌面環境配置指南 一、Linux 開機運行級別(Runlevel) 在傳統的 Linux 系統(如 SysV init 初始化系統)中,運行級別定義了系統啟動時加載的服務和資源。常見的運行級別如下: 運行級別模式用途0Halt(停機模式)關閉系統1Single User Mode…

Spring Cloud Gateway配置雙向SSL認證(完整指南)

本文將詳細介紹如何為Spring Cloud Gateway配置雙向SSL認證,包括證書生成、配置和使用。 目錄結構 /my-gateway-project ├── /certs │ ├── ca.crt # 根證書 │ ├── ca.key # 根私鑰 │ ├── gateway.crt # 網關證書 │ ├── …

【虛幻5藍圖Editor Utility Widget:創建高效模型材質自動匹配和資產管理工具,從3DMax到Unreal和Unity引擎_系列第二篇】

虛幻5藍圖Editor Utility Widget 一、基礎框架搭建背景&#xff1a;1. 創建Editor Utility Widget2.根控件選擇窗口3.界面功能定位與階段4.查看繼承樹5.目標效果 二、模塊化設計流程1.材質替換核心流程&#xff1a;2.完整代碼如下 三、可視化界面UI布局1. 添加標題欄2. 構建滾動…

LabVIEW實現DMM與開關模塊掃描測量

該程序基于 LabVIEW&#xff0c;用于控制數字萬用表&#xff08;DMM&#xff09;與開關模塊進行測量掃描。通過合理配置觸發源、測量參數等&#xff0c;實現對多路信號的自動化測量與數據獲取&#xff0c;在電子測試、工業測量等領域有廣泛應用。 ? 各步驟功能詳解 開關模塊…

OpenAvatarChat要解決UnicodeDecodeError

錯誤信息如下 ailed to import handler module client/h5_rendering_client/client_handler_lam Traceback (most recent call last):File "E:\Codes\Python\aigc\OpenAvatarChat\src\demo.py", line 82, in <module>main()File "E:\Codes\Python\aigc\O…

數據庫中的主鍵(Primary Key)

數據庫中的主鍵&#xff08;Primary Key&#xff09; 主鍵是數據庫表中用于唯一標識每一行記錄的一個或多個列的組合&#xff0c;是關系型數據庫中的重要概念。 主鍵的核心特性 唯一性&#xff1a;主鍵值必須唯一&#xff0c;不能重復非空性&#xff1a;主鍵列不能包含NULL值…

MySQL 9.3 正式發布!備份、用戶管理與開發支持迎來革命性升級

開源數據庫領域的標桿產品MySQL迎來重大更新——MySQL 9.3正式發布&#xff01;作為企業級數據庫的“扛把子”&#xff0c;此次版本更新聚焦備份效率、用戶管理精細化、開發支持增強三大核心領域&#xff0c;同時在高可用性和性能優化上實現突破。以下為你逐一解讀新版本的亮點…