Centos下安裝python的MySQLdb模組若干錯誤總結
1、下載,解壓python-mysql
2、執行python setup.py install
3、Error1: 報錯mysql_config not found
首先查詢mysql_config的位置,使用find / -name mysql_config
其次、修改setup_posix.py檔案
mysql_config.path = "mysql_config" 改為
mysql_config.path ="/usr/local/mysql/bin/mysql_config" # 這裡的路徑是自己系統的mysql_config的路徑
4、Error2:
In file included from _mysql.c:29: pymemcompat.h:10:20: error: Python.h: No such file or directory _mysql.c:30:26: error: structmember.h: No such file or directory In file included from /usr/include/mysql/mysql.h:44, from _mysql.c:40: . . . _mysql.c:2808: warning: return type defaults to 'int' _mysql.c: In function 'DL_EXPORT': _mysql.c:2808: error: expected declaration specifiers before 'init_mysql' _mysql.c:2886: error: expected '{' at end of input error: command 'gcc' failed with exit status 1
需要安裝python-devel
yum install python-devel
5、Error3:在執行,importMySQLdb 時報ImportError: libmysqlclient.so.18:cannot open shared object file: No such file or directory
將安裝的mysql的lib中的libmysqlclient.so.18做個然連線就ok了,
>>> find / -name libmysqlclient.so.18
>>> ln -s /usr/local/server/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
>>> ldconfig # 立即生效
6、Error4:在執行,importMySQLdb 時報ImportError: libssl.so.1.0.0: cannotopen shared object file: No such file or directory
find / -name libssl.so.1.0.0
ln -s /opt/lamp/lib/libssl.so.1.0.0 /usr/lib
ldconfig
///////////////////////// 分割線 //////////////////////////////
(2014-03-08更新,開源中國社群)
7、使用一種完美解決python-mysqldb安裝的方式:(不要問,為什麼,反正運行了,就可以避免很多錯誤)
yum install gcc python-devel mysql-devel -y
上面執行過後,會解決一些MySQLdb使用到的一些依賴;
8、如果你是在Centos下安裝的MySQLdb,安裝完成後,在/usr/lib64/python2.6/site-packages/生成相應的egg檔案,我使用的是1.2.5;可能在使用apache部署投入生產環境使用的時候,會有
kages/setuptools-2.2-py2.6.egg/pkg_resources.py:991: UserWarning: /root/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
那就需要在apache連線python模組時指定PYTHON_EGG_CACHE,我使用的是{{ 專案名稱 }}/wsgi.py的方式做連線,在wsgi.py裡新增:
os.environ['PYTHON_EGG_CACHE'] = '/tmp/.python-eggs'
持續更新。。。