mac安裝MySQLdb(mysql-python模塊)


 

折騰了有一會,網上資料很多,但是在實際安裝時就會發現有很多坑,如下實戰操作可行。供參考。

Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-IQ2MXF/mysql-python/

 

正式的解決方案來了:

 

1、去官網下載MySQL:https://dev.mysql.com/downloads/mysql/,下載后直接點擊安裝即可,安裝時選用默認路徑即可。

 

        

 

2、默認的安裝路徑是:/usr/local/mysql,然后我嘗試使用命令sudo pip install mysql-python,仔細看看報錯: 

 

sh: mysql_config: command not found Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/tmp/pip-install-IQ2MXF/mysql-python/setup.py", line 17, in <module> metadata, options = get_config() File "setup_posix.py", line 43, in get_config libs = mysql_config("libs_r") File "setup_posix.py", line 25, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,)) EnvironmentError: mysql_config not found ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-IQ2MXF/mysql-python/

 

EnvironmentError: mysql_config not found,找不到這個配置文件!

 

3、查看bash_profile文件是否存在

  此時若你已經存在了bash_profile文件,則直接使用命令:open -e .bash_profile來打開,若無此文件,則使用

命令:touch .bash_profile新建

 

4、編輯這個文件:

     添加內容(/usr/local/mysql/bin和/usr/local/mysql/lib/是我的mysql路徑下的文件夾):

請復制這些內容到你的:bash_profile文件中。 PATH="/usr/local/mysql/bin:${PATH}" export PATH export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/ export VERSIONER_PYTHON_PREFER_64_BIT=yes export VERSIONER_PYTHON_PREFER_32_BIT=no

 

5、再始環境變量生效

     source ~/.bash_profile

 

6、最后,超關鍵,使用

      sudo pip install mysql-python


好了,成功。

 

參考鏈接:https://www.jianshu.com/p/7573c2784ad8

 

 


免責聲明!

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



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