[Pythonmac-SIG] problem importing python packages

Magladry, Stephen stephenm@humongous.com
Wed, 4 Sep 2002 10:41:27 -0700


I'm having problems with importing  Python packages and the
PythonInterpreter. Here is 
a minimal project that duplicates the problem.


First I have a Python Package "bitt".

file "__init__.py" in folder "bitt" in folder "Python 2.2.1" in folder
"Applications"

__init__.py has the following content:



~~~ startFile __init__.py  ~~~~~~~~~~~~~~~~~~~`
import sys

print "initing bitt"

if( __name__ == "__main__" ):
	print "WARNING: don't do this"
	sys.exit()

~~~   endFile __init__.py  ~~~~~~~~~~~~~~~~~~~~







There is a second file, a Python source file, "btest.py".

file "btest.py" in folder "Python 2.2.1" in folder "Applications"



btest.py has the following content:



~~~ startFile btest.py  ~~~~~~~~~~~~~~~~~~~`

def bitt():
	import bitt
	print "I'm back"
	
if ( __name__=="__main__" ):
	bitt()
	
~~~   endFile btest.py  ~~~~~~~~~~~~~~~~~~~~




if I drop btest.py on the PythonInterpreter, I get the following output:


initing bitt
I'm back



if I open the PythonInterpreter and then do the following commands,

>>> import btest
>>> btest.bitt()

I get these results:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "btest2.py", line 3, in bitt
    import bitt
ImportError: No module named bitt


So the PythonInterpreter can not find the Python Package "bitt" from the
imported module.


The importing method works with the Python IDE, but I need this to work 
with the PythonInterpreter. Also, this same code works on Windows either 
using "btest.py" as a parameter to Python or importing it into the Python
shell.


Anyone know what is going wrong and how to fix it? Can anyone give me some
hints where to 
look to fix this problem?



Thanks,


Stephen Magladry