sudo easy_install MySQL-python
报错信息中有这两行,没有mysql_config命令python
sh: mysql_config: command not found
EnvironmentError: mysql_config not foundmysql
先找下这个命令在哪里,查到是mysql/bin下命令。难道mysql没有添加到个人环境变量path中。
检查下path,多是没有配置这个命令sql
$ echo $PATH /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/bin: /usr/local/bin: /usr/bin: /bin: /usr/sbin: /sbin: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc: /Users/chopin/apache-maven-3.3.9/bin:
确实没有配置,知道了这个问题解决起来就好办了。shell
添加一个软连接,将命令放到环境变量/usr/local/bin下macos
ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/mysql_config
而后再执行安装命令apache
$sudo easy_install MySQL-python 16 warnings generated. zip_safe flag not set; analyzing archive contents... Adding MySQL-python 1.2.5 to easy-install.pth file Installed /Library/Python/2.7/site-packages/MySQL_python-1.2.5-py2.7-macosx-10.10-intel.egg Processing dependencies for MySQL-python Finished processing dependencies for MySQL-python
看到安装提示有16个警告,安装的版本是1.2.5app
使用help()方法来检测模块是否安装。maven
$ python Python 2.7.10 (default, Jul 14 2015, 19:46:27) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> help() //输入模块名 help> MySQLdb problem in MySQLdb - <type 'exceptions.ImportError'>: dlopen(/Users/chopin/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.10-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib Referenced from: /Users/chopin/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.10-intel.egg-tmp/_mysql.so Reason: image not found
又发现了错误,Library not loaded: libmysqlclient.18.dylib
找不到libmysqlclient.18.dylib这个库文件。
实际上这个文件在/usr/local/mysql/lib下的,因此又是文件路径引用错误。
再次作个软连接ui
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
再次在help下输入模块名MySQLdb,会输出说明文档,帮组熟悉模块内容。code
help> MySQLdb ... PACKAGE CONTENTS connections constants (package) converters cursors release times ... //退出文档按q //退出help输入quit help> quit //退出python输入 >>>exit()
好了,大功告成,能够尽情的开发了。