一、下載,解壓python-mysql
python
二、運行python setup.py installmysql
三、Error1: 報錯mysql_config not foundsql
首先查找mysql_config的位置,使用find / -name mysql_configshell
其次、修改setup_posix.py文件apache
mysql_config.path = "mysql_config" 改成ide
mysql_config.path = "/usr/local/mysql/bin/mysql_config" # 這裏的路徑是本身系統的mysql_config的路徑spa
四、Error2: .net
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-develcode
yum install python-devel
五、Error3:在運行,import MySQLdb 時報ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directoryserver
將安裝的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 # 當即生效
六、Error4:在運行,import MySQLdb 時報ImportError: libssl.so.1.0.0: cannot open 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更新,開源中國社區)
七、使用一種完美解決python-mysqldb安裝的方式:(不要問,爲何,反正運行了,就能夠避免不少錯誤)
yum install gcc python-devel mysql-devel -y
上面運行事後,會解決一些MySQLdb使用到的一些依賴;
八、若是你是在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'
持續更新。。。
鄭重聲明,未經本人容許,不得任何形式的轉載和copy,請尊重原版;http://my.oschina.net/shniu/admin/edit-blog?blog=205379