Mac環(huán)境下树酪,使用pycharm的python虛擬環(huán)境安裝MySQLdb模塊包遇到的問題
錯(cuò)誤:
ImportError: No module named MySQLdb.constants
EnvironmentError: mysql_config not found
_mysql.c:44:10: fatal error: 'my_config.h' file not found
因?yàn)閜ycharm編輯器中直接安裝會報(bào)錯(cuò),所以找到對應(yīng)的python虛擬環(huán)境目錄(對應(yīng)的項(xiàng)目目錄/venv/bin)仁卷,使用下面命令安裝MySQL-python
./python -m pip install MySQL-python
報(bào)錯(cuò)信息:EnvironmentError: mysql_config not found
需要安裝mysql依賴
brew install mysql
繼續(xù)安裝MySQL-python
報(bào)錯(cuò)信息:_mysql.c:44:10: fatal error: 'my_config.h' file not found
查詢發(fā)現(xiàn)需要安裝mysql-connector-c纵刘,使用mysql-client替代已經(jīng)廢棄的mysql-connector-c
brew install mysql-connector-c
下載MySQL-python安裝包解壓
找到/opt/homebrew/Cellar/mysql-client/8.0.29/include目錄
cp mysql.h 到MySQL-python目錄下 my_config.h
項(xiàng)目目錄下的虛擬環(huán)境/venv/bin/python setup.py build
項(xiàng)目目錄下的虛擬環(huán)境/venv/bin/python setup.py install
然后就大功告成啦~開心
最后代碼還是跑不起來邀窃,因?yàn)閙1芯片不支持T_T
mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')