Why do I get an import error on this?

Ron Adam rrr at ronadam.com
Fri Oct 7 13:07:10 EDT 2005


Steve wrote:
> I'm trying to run a Python program on Unix and I'm encountering some
> behavior I don't understand.  I'm a Unix newbie, and I'm wondering if
> someone can help.
> 
> I have a simple program:
> ____________________________________________
> 
> #! /home/fergs/python/bin/python
> import sys, os
> import cx_Oracle
> ____________________________________________
> 
> If I run it through the Python interpreter, this way:
> 
>  >> python test.py
> 
> it runs fine.
> 
> But if I try to run it as an executable script, this way:
> 
>  >> test.py
> 
> I get an import error that says it can't find cx_Oracle.
> 
> Why does it behave differently when I run it in these two ways, and
> what do I need to do to make it run successfully either way?

I ran across something similar with using py2exe.  I think it occurs 
when there are more than one file with the same name in different 
locations in the search path.  Try renaming cx_Oracle to _cx_Oracle then 
import as...

import _cx_Oracle as cx_Oracle

Of course your problem might be entirely different. But this might help.

Cheers,
Ron








More information about the Python-list mailing list