Traceback when trying to run script from cron?

E

erikcw

Hi all,

When trying to run this python script from cron, I get the following
error:


Traceback (most recent call last):
File "/home/lybp/public_html/wa/wa.py", line 14, in ?
import MySQLdb
ImportError: No module named MySQLdb

The cron command is python /home/lybp/public_html/wa/wa.py

Any idea why MySQLdb wouldn't like this?

Thanks!
Erik
 
D

Dennis Lee Bieber

The cron command is python /home/lybp/public_html/wa/wa.py

Any idea why MySQLdb wouldn't like this?
Does the cron service run with the same PYTHONPATH? Stuff in a
"print sys.path" (or a write to some file you can later examine) before
the deadly import, and compare direct invocation with the cron
invocation.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
E

erikcw

Does the cron service run with the same PYTHONPATH? Stuff in a
"print sys.path" (or a write to some file you can later examine) before
the deadly import, and compare direct invocation with the cron
invocation.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/

You're right. Something is not right with my sys.path.

cron:
'/home/lybp/public_html/winneralert', '/usr/lib/python2.2', '/usr/lib/
python2.2/plat-linux2', '/usr/lib/python2.2/lib-tk', '/usr/lib/
python2.2/lib-dynload', '/usr/lib/python2.2/site-packages']
Traceback (most recent call last):
File "/home/lybp/public_html/winneralert/wa.py", line 18, in ?
import MySQLdb
ImportError: No module named MySQLdb


SHELL:
# python wa.py
['/home/lybp/public_html/winneralert', '/usr/local/lib/python2.4/site-
packages/setuptools-0.6c5-py2.4.egg', '/usr/local/lib/python2.4/site-
packages/MySQL_python-1.2.2-py2.4-linux-i686.egg', '/usr/local/lib/
python24.zip', '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/
plat-linux2', '/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/
python2.4/lib-dynload', '/usr/local/lib/python2.4/site-packages']
+OK Hello there.

Why isn't cron able to import the MySJL module? How do I make this
work? (newbie)

Thanks!
Erik
 
C

Carsten Haese

You're right. Something is not right with my sys.path.

cron:
'/home/lybp/public_html/winneralert', '/usr/lib/python2.2', '/usr/lib/
python2.2/plat-linux2', '/usr/lib/python2.2/lib-tk', '/usr/lib/
python2.2/lib-dynload', '/usr/lib/python2.2/site-packages']
Traceback (most recent call last):
File "/home/lybp/public_html/winneralert/wa.py", line 18, in ?
import MySQLdb
ImportError: No module named MySQLdb


SHELL:
# python wa.py
['/home/lybp/public_html/winneralert', '/usr/local/lib/python2.4/site-
packages/setuptools-0.6c5-py2.4.egg', '/usr/local/lib/python2.4/site-
packages/MySQL_python-1.2.2-py2.4-linux-i686.egg', '/usr/local/lib/
python24.zip', '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/
plat-linux2', '/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/
python2.4/lib-dynload', '/usr/local/lib/python2.4/site-packages']
+OK Hello there.

Why isn't cron able to import the MySJL module? How do I make this
work? (newbie)

You have two Python versions installed on your system. Cron picks the
system-installed Python 2.2 in /usr, whereas your shell picks the
installation of Python 2.4 in /usr/local. Obviously, your Python 2.2
installation doesn't know MySQL, your Python 2.4 installation does.

Your cron script needs to set the PATH environment variable correctly to
include /usr/local/bin before /usr/bin so that it'll launch the correct
Python version.

HTH,

Carsten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top