468,136 Members | 1,452 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,136 developers. It's quick & easy.

Module import via sys.path and py2exe

Hi,

i have a program with is built like this:
startup.py
dir1/__init__.py
dir1/file1.py
dir2/__init__.py
dir2/file2.py
dir3/__init__.py
dir3/file3.py

The program works but now i want to add the functionality into an
existing program 2. This is program 2:

program2.py
program2dir1/__init__.py
program2dir1/file4.py

When i copy the directories over i get this situation:

program2.py
program2dir1/__init__.py
program2dir1/file4.py
program1/__init__.py
program1/dir1/__init__.py
program1/dir1/file1.py
program1/dir2/__init__.py
program1/dir2/file2.py
program1/dir3/__init__.py
program1/dir3/file3.py

However, i need to specify this in program2.py or i can't use the files 1-3:
import sys
sys.path.append('program1')
import program1.dir1.file1 as f1

Then i can use the functionality of the first program in the second.

Now for my questions:

1. Is this the correct way or is there an easier/more logical sollution.
Now all __init__.py file are empty

2. As said this works but when i make a standalone of program2 it
doesn't find any of the program1 files:
Traceback (most recent call last):
File "start.py", line 20, in ?
File "windows\windowmain.pyo", line 59, in ?
File "program1\__init__.pyo", line 2, in ?
File "program1\dir1\__init__.pyo", line 1, in ?
File "program1\dir1\file1.pyo", line 28, in ?
ImportError: No module named dir2.file2

dir2.file2 is imported in file1.py as import dir2.file2.
So something in my setup script is wrong. How can i make sure all file
of program1 are also added?

Excerpt of setup.py
....
py_modules=['start'],
packages=['database','dialogs','export','graphics','localuti ls','windows'],
....
If i specify program1 as module or as package or program1.dir1 and so on
doesn't seem to help.

Any ideas?

Thanks
Benedict
Sep 22 '05 #1
2 2465
flupke wrote:
Hi,

i have a program with is built like this:
startup.py
dir1/__init__.py
dir1/file1.py
dir2/__init__.py
dir2/file2.py
dir3/__init__.py
dir3/file3.py

The program works but now i want to add the functionality into an
existing program 2. This is program 2:

program2.py
program2dir1/__init__.py
program2dir1/file4.py

When i copy the directories over i get this situation:

program2.py
program2dir1/__init__.py
program2dir1/file4.py
program1/__init__.py
program1/dir1/__init__.py
program1/dir1/file1.py
program1/dir2/__init__.py
program1/dir2/file2.py
program1/dir3/__init__.py
program1/dir3/file3.py

However, i need to specify this in program2.py or i can't use the files
1-3:
import sys
sys.path.append('program1')
import program1.dir1.file1 as f1

Then i can use the functionality of the first program in the second.

Now for my questions:

1. Is this the correct way or is there an easier/more logical sollution.
Now all __init__.py file are empty

2. As said this works but when i make a standalone of program2 it
doesn't find any of the program1 files:
Traceback (most recent call last):
File "start.py", line 20, in ?
File "windows\windowmain.pyo", line 59, in ?
File "program1\__init__.pyo", line 2, in ?
File "program1\dir1\__init__.pyo", line 1, in ?
File "program1\dir1\file1.pyo", line 28, in ?
ImportError: No module named dir2.file2

dir2.file2 is imported in file1.py as import dir2.file2.
So something in my setup script is wrong. How can i make sure all file
of program1 are also added?

Excerpt of setup.py
...
py_modules=['start'],
packages=['database','dialogs','export','graphics','localuti ls','windows'],
...
If i specify program1 as module or as package or program1.dir1 and so on
doesn't seem to help.

Any ideas?

Thanks
Benedict


I forgot to add that if i check the shared.lib py2exe creates, the
program1 dir and subdirs/files are there so they are included in the
package.

Benedict
Sep 22 '05 #2
flupke wrote:
<snip>
I forgot to add that if i check the shared.lib py2exe creates, the
program1 dir and subdirs/files are there so they are included in the
package.

Benedict


Hi,

i solved it by adding the same import statement to the py2exe setup.py
script as in my code:

import sys
sys.path.append('program1')

I'm still not sure though that the way i'm adding the module in the
first place is correct but it seems to work okay.

Regards,
Benedict
Sep 26 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Alessandro Crugnola *sephiroth* | last post: by
1 post views Thread by Olav | last post: by
2 posts views Thread by Marc Ederis | last post: by
reply views Thread by Thomas Heller | last post: by
6 posts views Thread by kimes | last post: by
70 posts views Thread by Michael Hoffman | last post: by
4 posts views Thread by vincehofmeister | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.