因为最近换了工作的原因,没有机会接触云计算,加上其他一些非技术原因,不方便在博客上面记录关键的东西,最近写得东西基本都是自己学习的积累,高手直接飘过即可。
最近在学习python的django架构,学到数据库连接这部分,需要import MySQLdb这个模块,系统自带没有安装,于是乎用最简单的方法安装
sudo easy_install mysql_python
顺利安装成功后,执行如下命令导入模块测试,发现仍旧报错
ClovemFongdeMacBook-Pro:~ bruce$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.9-intel/egg/MySQLdb/__init__.py", line 19, in <module>
File "build/bdist.macosx-10.9-intel/egg/_mysql.py", line 7, in <module>
File "build/bdist.macosx-10.9-intel/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/bruce/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.9-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/bruce/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.9-intel.egg-tmp/_mysql.so
Reason: image not found
解决方法:创建软连接或者修改环境变量
ClovemFongdeMacBook-Pro:~ bruce$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
然后就OK了
ClovemFongdeMacBook-Pro:~ bruce$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>
>>>
>>>
>>> dir(MySQLdb)
['BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'DATETIME', 'DBAPISet', 'DataError', 'DatabaseError', 'Date', 'DateFromTicks', 'Error', 'FIELD_TYPE', 'IntegrityError', 'InterfaceError', 'InternalError', 'MySQLError', 'NULL', 'NUMBER', 'NotSupportedError', 'OperationalError', 'ProgrammingError', 'ROWID', 'STRING', 'TIME', 'TIMESTAMP', 'Time', 'TimeFromTicks', 'Timestamp', 'TimestampFromTicks', 'Warning', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__revision__', '__version__', '_mysql', 'apilevel', 'connect', 'connection', 'constants', 'debug', 'escape', 'escape_dict', 'escape_sequence', 'escape_string', 'get_client_info', 'paramstyle', 'release', 'result', 'server_end', 'server_init', 'string_literal', 'test_DBAPISet_set_equality', 'test_DBAPISet_set_equality_membership', 'test_DBAPISet_set_inequality', 'test_DBAPISet_set_inequality_membership', 'thread_safe', 'threadsafety', 'times', 'version_info']