packaging python code in zip file

M

mark jason

hi,
I have created a python app in eclipse pydev .The app is structured as
below..

mypackage
|______ __init__.py
|______ driver.py
|______ helper.py
|______ utils.py

The driver.py has the main program.I have added if
__name__=="__main__" block in the

driver.py and pydev's run configuration has the following values,
Project : myproject
Main Module :${workspace_loc:myproject/src/mypackage/driver.py}
So,the app runs in pydev without any problems.

Then I thought of providing the modules as a zip file.So I created a
zip file containing
mypackage directory.The user should be able to unzip the zip file and
run the application from command line .

What bothers me is that ,the user will have to cd to mypackage folder
and run python driver.py..
This doesn't look like the proper way..
I also thought of putting the driver,helper,utils modules in a folder
called mycode and zipping it without the __init__.py file .
I am not sure which is the correct way.
Can somebody advise me as to how I can package it better?

thanks,

mark
 
P

Peter Otten

mark said:
hi,
I have created a python app in eclipse pydev .The app is structured as
below..

mypackage
|______ __init__.py
|______ driver.py
|______ helper.py
|______ utils.py

The driver.py has the main program.I have added if
__name__=="__main__" block in the

driver.py and pydev's run configuration has the following values,
Project : myproject
Main Module :${workspace_loc:myproject/src/mypackage/driver.py}
So,the app runs in pydev without any problems.

Then I thought of providing the modules as a zip file.So I created a
zip file containing
mypackage directory.The user should be able to unzip the zip file and
run the application from command line .

What bothers me is that ,the user will have to cd to mypackage folder
and run python driver.py..
This doesn't look like the proper way..
I also thought of putting the driver,helper,utils modules in a folder
called mycode and zipping it without the __init__.py file .
I am not sure which is the correct way.
Can somebody advise me as to how I can package it better?

If you put a __main__.py file at the top level you can run the zip archive
directly (requires Python 2.6):

$ echo 'import alpha
print "main"' > __main__.py
$ mkdir alpha
$ echo 'print "init alpha"' > alpha/__init__.py
$ zip -r demo .
adding: alpha/ (stored 0%)
adding: alpha/__init__.py (stored 0%)
adding: __main__.py (stored 0%)
$ rm -rf __main__.py alpha/
$ ls
demo.zip
$ python demo.zip
init alpha
main

Peter
 

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

Members online

No members online now.

Forum statistics

Threads
474,053
Messages
2,570,431
Members
47,075
Latest member
TysonV438

Latest Threads

Top