mac系統安裝mysqlclient的一些坑(附解決方法)


最近在學習Django,做ORM模型實驗時候,我看老師用到數據庫了,然后windows電腦就 pip install mysqlclient 安裝就完事了。

我的是mac,到我這就悲劇了,一個坑接着一個坑跳,我看網上有的人因為這個東西搞了一天的都有(手動“哭”)!

直接上方法,不錯,就是mysqlclient源碼github目錄直接有解決方法,操作標紅的部分即可。

 --------------------------------------------------------

Install

Prerequisites

You may need to install the Python and MySQL development headers and libraries like so:

  • sudo apt-get install python-dev libmysqlclient-dev # Debian / Ubuntu
  • sudo yum install python-devel mysql-devel # Red Hat / CentOS
  • brew install mysql-connector-c # macOS (Homebrew) (Currently, it has bug. See below)

On Windows, there are binary wheels you can install without MySQLConnector/C or MSVC.

Note on Python 3 : if you are using python3 then you need to install python3-dev using the following command :

sudo apt-get install python3-dev # debian / Ubuntu

sudo yum install python3-devel # Red Hat / CentOS

Note about bug of MySQL Connector/C on macOS

See also: https://bugs.mysql.com/bug.php?id=86971

Versions of MySQL Connector/C may have incorrect default configuration options that cause compilation errors when mysqlclient-python is installed. (As of November 2017, this is known to be true for homebrew's mysql-connector-cand official package)

Modification of mysql_config resolves these issues as follows.

Change

# on macOS, on or about line 112: # Create options libs="-L$pkglibdir" libs="$libs -l " 

to

# Create options libs="-L$pkglibdir" libs="$libs -lmysqlclient -lssl -lcrypto"

 --------------------------------------------------------

解決方案:

 步驟一

安裝mysql-connector-c

brew install mysql-connector-c

步驟二

修改mysql_config,這個文件在/usr/local/bin/mysql_config,實際在/usr/local/Cellar/mysql/8.0.23_1/bin/mysql_config

直接修改

# 記得sudo,不然沒有權限,大概在文件120行左右(:set number 顯示行號)

sudo vi /usr/local/bin/mysql_config
 # Create options libs="-L$pkglibdir" libs="$libs -l " 

# 修改為

# Create options libs="-L$pkglibdir" libs="$libs -lmysqlclient -lssl -lcrypto"

步驟三

pip install mysqlclient

 

問題:

還遇到一個坑,客戶端就是下載不下來。不用想了,換個源吧,我換了中科大的源解決了

解決方案:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

 

 

參考鏈接:

https://my.oschina.net/u/914655/blog/1594267

https://zhuanlan.zhihu.com/p/111014448


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM