[Spambayes] ImportError on new install

Tony Meyer tameyer at ihug.co.nz
Tue Feb 8 22:54:12 CET 2005

> I've used sb_impafilter.py with excellent results on my older 
> windows PC for several months, but recently got a new windows 
> PC and after downloding a fresh copy of Python24 & Spambayes 
> source, I'm getting an error:
> C:\Program Files\spambayes-1.0.3\scripts>c:\python24\python 
> sb_imapfilter.py -b
> Traceback (most recent call last):
>   File "sb_imapfilter.py", line 119, in ?
>     from spambayes.Options import options, get_pathname_option
> ImportError: No module named spambayes.Options
> I'm a reasonably savvy computer user, but completely new to 
> python, so I may need to be spoon-fed a bit on the Python end. 

Python needs to import the "spambayes" package, and doesn't know where it
is.  It will search the current working directory and sys.path, so you want
to get the package there somehow.

> I figured out a workaround but I'm not sure if it is the most 
> graceful option. After scanning a python tutorial, I started 
> python interactively, and did:
> import sys
> sys.path.append("\program files\spambayes-1.0\")
> [ctrl-z]
> Then I altered my config.bat as follows:
> cd c:\program files\spambayes-1.0.3
> c:\python24\python .\scripts\sb_imapfilter.py -b
> Seems like a bit of a kludge, bu I'm working now.
> I just noticed that while I was adding spambayes 1.0 to the 
> path, I was referring to 1.0.3 in the bat file. So apparently 
> my path append had nothing to do with my success but changing 
> my working directory made the relative paths work out.

Yes; because Python looks in the current working directory, it finds the
spambayes package directory that it needs.

This is a perfectly valid way of solving the problem.  Two others are:

  1.  Put the C:\Program Files\spambayes-1.0.3' directory in the PYTHONPATH
environment variable.  The contents of that are added to sys.path when
Python starts up.

  2.  Run "setup.py install" - this copies the required spambayes files to
the C:\Python24\Lib\site-packages directory, which is also searched for
required packages.

> BTW, when looking at the comments in sb_imapfilter.py, I note 
> that it says IMAP over SSL is relatively untested. I've been 
> using IMAP/SSL for months with no problem and will continue 
> to do so, so it is now somewhat more tested.

Many thanks for the feedback.

> Congrats to the author for a pretty clean alpha version.

Thanks - although the credit for SSL working so smoothly really belongs with
those that did a good job with the underlying Python imaplib module.

Please always include the list (spambayes at python.org) in your replies
(reply-all), and please don't send me personal mail about SpamBayes.
http://www.massey.ac.nz/~tameyer/writing/reply_all.html explains this.

More information about the Spambayes mailing list