之前安裝MySQLdb之後發現一個很奇怪的狀況
在Python直譯器底下可以正常import MySQLdb模組
但是在uwsgi以及nginx環境下卻出現以下錯誤:
ImportError: No module named MySQLdb
查過很多資料上python.tw請教大家後發現
在直譯器底下sys.path的值為:
['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/local/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages', '/usr/lib/pymodules/python2.6', '/usr/lib/pymodules/python2.6/gtk-2.0']
[".", "/var/www/app/lib/python2.6", "/var/www/app", "/usr/lib/python2.6", "/usr/lib/python2.6/plat-linux2", "/usr/lib/python2.6/lib-tk", "/usr/lib/python2.6/lib-old", "/usr/lib/python2.6/lib-dynload"]
很明顯的不一樣,而剛好MySQLdb安裝的位置就在
/usr/lib/pymodules/python2.6
所以才會出現一邊可以另外一邊卻不行的情況
解決的方法其實很簡單
直接編輯/etc/uwsgi-python/apps-enabled/uwsgi.xml
新增以下藍色字串
<uwsgi>
<socket>/tmp/uwsgi.sock</socket>
<master/>
<pythonpath>/usr/lib/pymodules/python2.6</pythonpath>
<limit-as>512</limit-as>
<processes>8</processes>
<gid>www-data</gid>
<uid>www-data</uid>
<memory-report/>
<vhost/>
<no-site/>
</uwsgi>
再重新啟動uwsgi即可
0 意見:
張貼留言