473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 2669
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: x-herbert | last post by:
Hi, I have a small test to "compile" al litle script as a WMI-Tester. The script include a wmi-wrapper and "insert" the Win32-modeles. here the code: my "WMI-Tester.py" ----- import wmi
6
by: Alessandro Crugnola *sephiroth* | last post by:
hi, i have already problems using py2exe.. i'm using python 2.2, wxPython and audiere for a little mp3 player.. once I've build the exe with py2exe, when launching the application: Traceback...
3
by: Paul | last post by:
Hi I'm trying to build a standalone COM exe server using Python 2.2 + Mark Hammond's windows extensions + Py2Exe. I've built the example linked on the Py2Exe homepage and get this error when...
1
by: Olav | last post by:
I'm having a problem when I try to make a standalone installation of a Python program using Tim Goldens WMI-module. The py2exe produce the exe-file as expected, but it fails to execute. I have...
2
by: Marc Ederis | last post by:
Hello, I'm trying to create an executable with py2exe, and it uses the odbc module. The script runs fine until I use py2exe on it and run the ..exe. Then I get: -- Traceback (most recent...
0
by: Thomas Heller | last post by:
Several users have been bitten by the incompatibility of py2exe and Jason Jorendorff's path module at http://www.jorendorff.com/articles/python/path/. I think I have found the bug in...
6
by: kimes | last post by:
I've just started digging into how python works.. I found that other mudules are clearly declared like one file per a module.. But the only os.path doesn't have their own file.. ye I know is...
70
by: Michael Hoffman | last post by:
Many of you are familiar with Jason Orendorff's path module <http://www.jorendorff.com/articles/python/path/>, which is frequently recommended here on c.l.p. I submitted an RFE to add it to the...
4
by: vincehofmeister | last post by:
Hey everyone: I am using py2exe and everything is working fine except one module, ClientCookie, found here: http://wwwsearch.sourceforge.net/ClientCookie/ Keeps coming up as not found no...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.