遇到的第一個問題
- 正常來說直接執行pip安裝,就是可以的,但是MySQL-python偏偏比較獨特
pip install MySQL-python
- 報錯
_mysql.c:44:10: fatal error: 'my_config.h' file not found #include "my_config.h" ^~~~~~~~~~~~~ 1 error generated. error: command 'cc' failed with exit status 1
解決第一個問題
- 執行
brew install mysql-connector-c
brew install mysql-connector-c
- 如果這一步直接完成,那就可以繼續
了 ,應該會成功pip install MySQL-python
- 但是我在這一步執行失敗了
遇到第二個問題
-
brew install mysql-connector-c
Error: Cannot install mysql-connector-c because conflicting formulae are installed. mysql: because both install MySQL client libraries Please `brew unlink mysql` before continuing.
解決第二個問題
- 按照報錯的提示,執行
brew unlink mysql
- 沒有發生什麼意外,執行完畢,繼續執行
brew install mysql-connector-c
- 'mysql-connector-c'安裝成功
-
,重新連接配接mysql(這一步我沒有做)brew link --overwrite mysql
- 然後再執行
,如果成功了就搞定了pip install MySQL-python
- 神奇的是,我在這一步又失敗了
遇到的第三個問題
- 上面的步驟走完以後,執行
,報錯pip install MySQL-python
Collecting mysql Downloading https://files.pythonhosted.org/packages/06/ef/c4efbf2a51fb46aba9be03a973638d9539c9ca10a5259b2cbb1a66133b2e/mysql-0.0.1.tar.gz Collecting MySQL-python (from mysql) Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/folders/zn/t8xxx4m149s9jqp1810ndrz80000gn/T/pip-install-oHMKPE/MySQL-python/setup.py", line 17, in <module> metadata, options = get_config() File "setup_posix.py", line 53, in get_config libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ] File "setup_posix.py", line 8, in dequote if s[0] in "\"'" and s[0] == s[-1]: IndexError: string index out of range
解決第三個問題
- 修改mysql的配置檔案
mysql_config
,修改前記得cp一下
執行
,檢視一下路徑mysql_config
- 打開檔案
,找到vim mysql_config
,改為libs="$libs -l "
libs="$libs -lmysqlclient -lssl -lcrypto "
libs="-L$pkglibdir" # libs="$libs -l " # 原來的 libs="$libs -lmysqlclient -lssl -lcrypto " # 更改後的 embedded_libs="-L$pkglibdir" embedded_libs="$embedded_libs -l "
- 再來一遍
pip install MySQL-python
- 終于成功了!可喜可賀!可喜可賀!
- 小心翼翼的試一下,
,真的成功了import MySQLdb
發現第四個問題
- 開始使用的時候,發現自己用的是
的環境,換成python2.x
繼續用python3.x
- 在
的時候又出問題了,import MySQLdb
ModuleNotFoundError: No module named 'MySQLdb'
- 嘗試使用
再安裝一次,報錯pip3 install MySQL-python
Collecting MySQL-python Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/folders/07/v8slhf9x5zsbbd8_9cd5ztnh0000gp/T/pip-install-oh_74ez5/MySQL-python/setup.py", line 13, in <module> from setup_posix import get_config File "/private/var/folders/07/v8slhf9x5zsbbd8_9cd5ztnh0000gp/T/pip-install-oh_74ez5/MySQL-python/setup_posix.py", line 2, in <module> from ConfigParser import SafeConfigParser ModuleNotFoundError: No module named 'ConfigParser' ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/07/v8slhf9x5zsbbd8_9cd5ztnh0000gp/T/pip-install-oh_74ez5/MySQL-python/
解決第四個問題
- 查到了原因,感到一陣陣的無語
In Python 3, ConfigParser has been renamed to configparser for PEP 8 compliance. It looks like the package you are installing does not support Python 3.
在Python3中,ConfigParser為了符合PEP8規範,已重命名為configparser。看起來你正在安裝的軟體包不支援Python3。
- 因為不支援python3,建議使用
,安裝也沒那麼多套路pip install pymysql
- 其實也找到了解決方案(沒有測試,我也不知道對不對,單純的記錄一下)
- 方法一, 修改six子產品為
try: import configparser except: from six.moves import configparser
- 方法二
cp /usr/local/lib/python3.7/configparser.py /usr/local/lib/python3.7/ConfigParser.py
- 方法一, 修改six子產品為
參考連結:
時光不寫部落格-_mysql.c:44:10:fatal error:'my_config.h'...