当我使用python控制台并使用
时import MySQLdb
没有错误发生。 当我使用bash脚本
时#!/usr/bin/python
import MySQLdb
我收到以下错误
File "./jaccard.py", line 2, in <module>
import MySQLdb
ImportError: No module named MySQLdb
打印sys.path
import sys; print(sys.path)
输出
'/Users/kinetechsolutions/Dropbox/Code', '/Library/Python/2.7/site-packages/pip-1.3.1-py2.7.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages'
和
MySQLdb.__file__
崩溃了python的命令行