Problem with Packages

Srikanth sri1025 at gmail.com
Thu Mar 8 00:37:51 EST 2007


Hi,

I am learning about Python packages and I am getting an ImportError
but I can't figure out the reason why.

I have three modules and they are stored in a directory hierarchy as:

my_apps
|
|--> mod3.py
|--> dir1/dir1_1/mod1.py
|--> dir2/dir2_2/mod2.py

mod1.py defines a function called add(num1, num2) and mod2.py defines
a function called multiply(num1, num2) and mod3.py makes use of the
two functions defined in mod1.py and mod2.py and mod3.py's contents is
as follows:

-----------------------------------------------
from dir1.dir1_1 import mod1
from dir2.dir2_2 import mod2

def main():
	print mod1.add(10, 34)
	print mod2.multiply(3, 6)

if __name__ == "__main__":
	main()
----------------------------------------------

And the directory my_apps is included in PYTHONPATH environment
variable, what am I doing wrong? I executed this code under PyDev and
it's working perfectly but when I run it outside of PyDev, it fails.

This is command I used to execute mod3.py:

C:\> python C:\my_apps\mod3.py

But I get the following error:
Traceback (most recent call last):
  File "c:\my_apps\mod3.py", line 1, in ?
    from dir1.dir1_1 import mod1
ImportError: No module named dir1.dir1_1

Thanks,
Srikanth




More information about the Python-list mailing list