mac 安裝 python mysqlclient 遇到的問題及解決方法

在 mac 上安裝 mysqlclient 遇到了一些問題,查找資料不少人都遇到了一樣的問題。經過資料和試驗,成功了。這裏記錄一下,但願幫到遇到一樣問題的人。python

本人使用python3, 安裝步驟以下:mysql

brew install mysql-connector-c

pip3 install mysqlclient

當執行 pip3 install mysqlclient 是出現錯誤:sql

➜ /usr/local/Cellar/mysql-connector-c/6.1.11/bin >pip3 install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-1.3.12.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/2w/56bgkvqd1xldl56fx_gx_fg00000gn/T/pip-build-f9admsgv/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/2w/56bgkvqd1xldl56fx_gx_fg00000gn/T/pip-build-f9admsgv/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/2w/56bgkvqd1xldl56fx_gx_fg00000gn/T/pip-build-f9admsgv/mysqlclient/setup_posix.py", line 54, in <listcomp>
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/2w/56bgkvqd1xldl56fx_gx_fg00000gn/T/pip-build-f9admsgv/mysqlclient/setup_posix.py", line 12, in dequote
        if s[0] in "\"'" and s[0] == s[-1]:
    IndexError: string index out of range

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

解決方案:mysql_configvim

執行:vim mysql_config,搜索 libs,或者114行,替換爲115行便可ui

112 # Create options
113 libs="-L$pkglibdir"
114 #libs="$libs -l "   ##源代碼
115 libs="$libs -lmysqlclient -lssl -lcrypto "  ##修改爲這樣

再次執行pip3 install mysqlclient,成功了。以下所示:spa

➜ /usr/local/Cellar/mysql-connector-c/6.1.11/bin >pip3 install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-1.3.12.tar.gz
Building wheels for collected packages: mysqlclient
  Running setup.py bdist_wheel for mysqlclient ... done
  Stored in directory: /Users/kk/Library/Caches/pip/wheels/df/bb/60/bf7c315cbe163515db1c846e4ffa5557dd785c82e82f3492e8
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.3.12
相關文章
相關標籤/搜索