Module import via sys.path and py2exe

F

flupke

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','localutils','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
 
F

flupke

flupke said:
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','localutils','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
 
F

flupke

flupke wrote:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top