By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,675 Members | 2,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,675 IT Pros & Developers. It's quick & easy.

execute python script question

P: n/a
Hello,

I have been developping something in python that has the following
hierarchy :

project/src/myPackage/
project/src/myPackage/__init__.py
project/src/myPackage/module1.py
project/src/myPackage/module2.py
project/src/myPackage/test/
project/src/myPackage/test/__init__.py
project/src/myPackage/test/test_module1.py
project/src/myPackage/test/test_module2.py
project/src/myPackage/mySubPackage/__init__.py
project/src/myPackage/mySubPackage/module1.py
project/src/myPackage/mySubPackage/test/
project/src/myPackage/mySubPackage/test/__init__.py
project/src/myPackage/mySubPackage/test/module1.py
....

up until now, I had been executing my modules from inside
project/src/myPackage/
but I realised that that is wrong (while implementing the test suite)
and that since all my modules had relative imports (if module2 needed
module1, it would just say : import module1) I changed them to
myPackage.module1 for example. Now my test suite is happy, I can say :
test.sh myPackage.test and it tests everything. The only problem now is
that I can't execute the scripts from inside or outside the myPackage
dir, I get this :

from outside :

Traceback (most recent call last):
File "myPackage/module1.py", line 15, in <module>
from myPackage import constants, utils
ImportError: No module named myPackage

or if from inside it :

Traceback (most recent call last):
File "module1.py", line 15, in <module>
from myPackage import constants, utils
ImportError: No module named myPackage

can anybody please help me? I don't think I understood the whole
package/module thing I think... I think some people do some sort of
importing in the __init__.py files but I'm not sure this helps in this case.

Thanks,
Gabriel

--
www.mydeskfriend.com
PSE - C (EPFL)
1015 Ecublens, Switzerland
Tel: +41 21 601 52 76
Mob: +41 76 442 71 62

Mar 10 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.