473,796 Members | 2,517 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Traceback when trying to run script from cron?

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

Apr 15 '07 #1
2 2486
On Apr 14, 10:50 pm, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
On 14 Apr 2007 18:56:00 -0700, "erikcw" <erikwickst...@ gmail.com>
declaimed the following in comp.lang.pytho n:
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
wlfr...@ix.netc om.com wulfr...@bestia ria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-a...@bestiaria. com)
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

Apr 17 '07 #2
On Tue, 2007-04-17 at 12:33 -0700, erikcw wrote:
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
Apr 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2159
by: lawrence k | last post by:
I've got a script called makeRss.php. It works fine if I try to open it with my browser. It makes an RSS feed for every page on my site. You can see it working here: http://www.autostratus.com/index.php?whatPage=makeRss It does just what I want it to do. However, I need for this script to get called every 15 minutes. So I set it up as a cron job. And cron doesn't like calling this thing. Cron
3
2584
by: dburdick | last post by:
I was referred to this forum as this may be a php specific problem. Some kind of configuration problem maybe. I have some php files that connect to a mysql database and are run as cron jobs. The scripts work fine when run via the command line as root, but when run via the cron they cause a mysql connection error. Call to undefined function: mysql_pconnect()
4
4416
by: J. Frank Parnell | last post by:
Hi there, I have a list of links which point to e.g. thescript.php?album=somePictures1 thescript.php?album=somePictures2 This list is about 3000 links. Each album may have 500 or more pictures in it. the script looks in the specified dir, and creates thumbnails if they are not present. So, displaying a particular album often takes quite a while. I've set the proper php.ini stuff to accomodate the long script_execution's. Thats all
0
3484
by: Cameron Simpson | last post by:
On 17Aug2008 21:25, John Nagle <nagle@animats.comwrote: Because $HOSTNAME is a bash specific variable, set by bash but NOT EXPORTED! Like $0 and a bunch of other "private" variables, subprocesses do not inherit this value. From "man bash": Shell Variables The following variables are set by the shell:
0
9684
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10182
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10017
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.