Cannot import mysql-python in crontab Mac OS

 ̄綄美尐妖づ 提交于 2019-12-06 06:29:35
Josh B

I solved this by using the following solution from : https://unix.stackexchange.com/questions/27289/how-can-i-run-a-cron-command-with-existing-environmental-variables

In my case it was because Cron didn't have access to my Environment variables that point to the correct place the Mysql library.

I used:

8 10 * * * . $HOME/.bash_profile; /Path/To/Script/pythonDbScript.py

I think you should check for your python version. On mac, it maybe installed several version of python. e.g. 2.5, 2.6, 2.7

When you run on terminal, you may using python2.6, but for the cron job, it my use the 2.7

use python -V to see which version of python are you using.

use which python to locate the python path

use shell autocomplete to see how many pythons did you install when you type python, then press "tab", you will find the result.

From the Mysqldb faq: http://mysql-python.sourceforge.net/FAQ.html

Another thing that can cause this: The MySQL libraries may not be on your system path.

Solutions:

set the LD_LIBRARY_PATH environment variable so that it includes the path to the MySQL libraries.

set static=True in site.cfg for static linking

This probably means that in your crontab (remember minimal shell environment) the mysql libraries are not accessible (not on the path, not in the LD_LIBRARY_PATH)

check your environment variables between the 'regular' shell and the 'crontab' shell

try below:

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!