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

distributing python software in jar like fashion

P: n/a
alf
Hi,

I have a small app which consist of a few .py files. Is there any way to
distribute it in jar like fashion as a single file I can just run python
on. I obviously look for platform independent solution.

Thx in advance, A.
Mar 15 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
ce
On Mar 15, 10:23 am, alf <ask@mewrote:
Hi,

I have a small app which consist of a few .py files. Is there any way to
distribute it in jar like fashion as a single file I can just run python
on. I obviously look for platform independent solution.

Thx in advance, A.
You can import from zip achieves as PEP 273, but to execute in the
same mechanism as the jar files, recently there is no way afaik.

ce (pain n d'ass)

Mar 15 '07 #2

P: n/a
alf <as*@me.xs4all.nlwrites:
I have a small app which consist of a few .py files. Is there any
way to distribute it in jar like fashion as a single file I can just
run python on. I obviously look for platform independent solution.
Python eggs are the platform-independent distributable single-file
archive. Given the way Python works, you can't simply execute them
as-is; you can, however, easily install them.

<URL:http://peak.telecommunity.com/DevCenter/EasyInstall>

--
\ "I think it would be a good idea." -- Mahatma Gandhi (when |
`\ asked what he thought of Western civilization) |
_o__) |
Ben Finney

Mar 15 '07 #3

P: n/a
Hi,

I have a small app which consist of a few .py files. Is there any way to
distribute it in jar like fashion as a single file I can just run python
on. I obviously look for platform independent solution.

Thx in advance, A.
"""
Author: Shane Geiger <sh**********@gmail.com>
Wed Mar 14 21:55:58 CDT 2007

Hi,

I have a small app which consist of a few .py files. Is there any way to
distribute it in jar like fashion as a single file I can just run python
on. I obviously look for platform independent solution.

------

Here's an answer to your question.
To use this script put it in the same directory as your .py files.
See the glob.glob function below if you want to specify a directory if
you want to change that.
(I tried to keep this example simple.)
Use the 'pack_mode()' and 'unpack_mode()' function calls at the bottom
of the script to
control it.

Note: I have not tested this on Windows.

"""
import base64
import string, os
import zipfile
import glob

def readfile(f): return open(f, "r").read()
def writefile(f, data, perms=750): open(f, "w").write(data) and
os.chmod(f, perms)

zip_file_name = 'python_modules.zip'
def write_test_modules():
## some test modules
srgexample="""
print "This was base64 encoded."
"""
srgexample2="""
print "This, too, was base64 encoded, and it was imported from a zip."
"""
writefile('srgexample.py',srgexample)
writefile('srgexample2.py',srgexample2)

def test_mode_cleanup():
os.remove('srgexample.py')
os.remove('srgexample2.py')
os.remove(zip_file_name)
def pack_mode():
"""
PACKING MODE:
(you could automate this procedure if it is important to you)
Zip the source files into one .zip file for easier handling.
Base64 encode the zip file to avoid problems of including the file.
Include the base64 representation of the zip file in a docstring, a
step that you could automate (but I haven't).
"""

write_test_modules()

# open the zip file for writing, and write stuff to it
import zipfile
import glob, os
# open the zip file for writing, and write stuff to it
file = zipfile.ZipFile(zip_file_name, "w")

# for name in glob.glob("*.py"):
for name in [x for x in glob.glob("*.py") if x != __file__]: #
dont' try to zip up this file
file.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
file.close()
## Here's how to watch what gets added
## open the file again, to see what's in it
#file = zipfile.ZipFile(zip_file_name, "r")
#for info in file.infolist():
# print info.filename, info.date_time, info.file_size,
info.compress_size

contents = open(zip_file_name, "r").read()
file_contents_in_base64 = base64.encodestring(contents)
print "Assign the following base64 encoded string to the
'python_modules_zip_base64' "
print " variable (after which you can use unpack mode)."

print file_contents_in_base64
# THEN MANUALLY ADD THAT to your main file.
# You could automatically edit the currently running file like this:

test_mode_cleanup()
def unpack_mode():
"""
UNPACKING MODE:
"""
python_modules_zip_base64="""
UEsDBBQAAAAIABq8bjYpPJvJJgAAACYAAAANAAAAc3JnZXhhbX BsZS5weeMqKMrMK1FQCsnILFYo
TyxWSEosTjUzUUjNS85PSU3RU+JSAAIAUEsDBBQAAAAIABq8bj Z5v8x4SAAAAEwAAAAOAAAAc3Jn
ZXhhbXBsZTIucHkdyTEKgDAMBdC9p/h0Dk7iSXqBaCJmaFPagODpFd/6Uh/WArlcNgnhTrh5Yuep
2wpth4sKgZvA4i+r3Ueo4BxewXisLznh8wJQSwECFAMUAAAACA AavG42KTybySYAAAAmAAAADQAA
AAAAAAAAAAAApIEAAAAAc3JnZXhhbXBsZS5weVBLAQIUAxQAAA AIABq8bjZ5v8x4SAAAAEwAAAAO
AAAAAAAAAAAAAACkgVEAAABzcmdleGFtcGxlMi5weVBLBQYAAA AAAgACAHcAAADFAAAAAAA=
"""
zip_file_contents = base64.decodestring(python_modules_zip_base64)
def writefile(f, data, perms=750): open(f, "w").write(data) and
os.chmod(f, perms)
writefile(zip_file_name,zip_file_contents)

# open the file, to see what's in it
#file = zipfile.ZipFile("test.zip", "r")
#for info in file.infolist():
# print info.filename, info.date_time, info.file_size,
info.compress_size

import sys
sys.path.insert(0, zip_file_name) # Add .zip file to front of path
import srgexample
import srgexample2

### you could even remove the file after using it
os.remove(zip_file_name)

pack_mode()
#unpack_mode()

--
Shane Geiger
IT Director
National Council on Economic Education
sg*****@ncee.net | 402-438-8958 | http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy
Mar 15 '07 #4

P: n/a
In article <Vs******************************@comcast.com>, alf <ask@mewrote:
>Hi,

I have a small app which consist of a few .py files. Is there any way to
distribute it in jar like fashion as a single file I can just run python
on. I obviously look for platform independent solution.

Thx in advance, A.
There is a new package that has been discussed here recently
called Squisher that should do what you want by packing things into
a single pyc file. There are still some minor issues that need to
be ironed out with running the pyc directly, but it should do
exactly what you want Real Soon Now.

http://groups.google.com/groups/sear...er&qt_s=Search

Gary Duzan
Motorola CHS
Mar 16 '07 #5

P: n/a
Were Python "eggs" a flop, or what?

We need to have one packager that everyone agrees on.
Otherwise, installs become a mess, and then you have to have
installers that handle multiple packagers.

John Nagle

Gary Duzan wrote:
In article <Vs******************************@comcast.com>, alf <ask@mewrote:
>>Hi,

I have a small app which consist of a few .py files. Is there any way to
distribute it in jar like fashion as a single file I can just run python
on. I obviously look for platform independent solution.

Thx in advance, A.


There is a new package that has been discussed here recently
called Squisher that should do what you want by packing things into
a single pyc file. There are still some minor issues that need to
be ironed out with running the pyc directly, but it should do
exactly what you want Real Soon Now.

http://groups.google.com/groups/sear...er&qt_s=Search

Gary Duzan
Motorola CHS

Mar 16 '07 #6

P: n/a
John Nagle wrote:
Were Python "eggs" a flop, or what?
No.
We need to have one packager that everyone agrees on.
Otherwise, installs become a mess, and then you have to have
installers that handle multiple packagers.
Eggs and Squisher are complementary tools. Squisher is good for distributing an
application with all of its dependencies in a single file; it is not a packager
or installer for libraries. Eggs are good for distributing libraries and plugins
and their dependencies.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Mar 16 '07 #7

P: n/a
Hi John,

I don't think eggs are a flop, however the pain they are trying to
solve is generally pretty minor in the Python world vs what we often
see with other languages. We're starting to see some push to move
more 3rd party libraries and frameworks to eggs (ie: Turbogears) and
as the developers get used to dealing with eggs we will reach a
critical mass.

The 2 main things holding eggs back, imo:
1. The eggs extensions aren't included in the Python std lib.
2. The Python std lib is fairly robust and we can accomplish a
significant amount of work without needing 3rd party code.

If eggs were included in the std lib, and/or the std lib was packaged
as eggs we'd see a far more rapid uptake. The key is getting the egg
extensions into the main distribution.

Chris

On 3/16/07, John Nagle <na***@animats.comwrote:
Were Python "eggs" a flop, or what?

We need to have one packager that everyone agrees on.
Otherwise, installs become a mess, and then you have to have
installers that handle multiple packagers.

John Nagle

Gary Duzan wrote:
In article <Vs******************************@comcast.com>, alf <ask@mewrote:
>Hi,

I have a small app which consist of a few .py files. Is there any way to
distribute it in jar like fashion as a single file I can just run python
on. I obviously look for platform independent solution.

Thx in advance, A.

There is a new package that has been discussed here recently
called Squisher that should do what you want by packing things into
a single pyc file. There are still some minor issues that need to
be ironed out with running the pyc directly, but it should do
exactly what you want Real Soon Now.

http://groups.google.com/groups/sear...er&qt_s=Search

Gary Duzan
Motorola CHS
--
http://mail.python.org/mailman/listinfo/python-list

--
"A little government and a little luck are necessary in life, but only
a fool trusts either of them." -- P. J. O'Rourke
Mar 16 '07 #8

P: n/a
In article <wb******************@newssvr25.news.prodigy.net >,
John Nagle <na***@animats.comwrote:
Were Python "eggs" a flop, or what?

We need to have one packager that everyone agrees on.
Otherwise, installs become a mess, and then you have to have
installers that handle multiple packagers.
I think the point about Squisher is that you don't have to
install it. You can either import it or run it directly. I'm mostly
interested in it as a way to package a script with a few Python
and C modules, dump it in the field, and run "python myscript.pyc"
to execute it, with no need for anything but the base Python to be
installed on the remote site, and just one file to copy.

Gary Duzan
Motorola CHS
Mar 17 '07 #9

P: n/a
ce wrote:
On Mar 15, 10:23 am, alf <ask@mewrote:
>Hi,

I have a small app which consist of a few .py files. Is there any way to
distribute it in jar like fashion as a single file I can just run python
on. I obviously look for platform independent solution.

Thx in advance, A.

You can import from zip achieves as PEP 273, but to execute in the
same mechanism as the jar files, recently there is no way afaik.
You could treat the collection of files as a Python package. You would
then add an __init__.py file to your collection and, in that __init__.py
arrange to initiate main.py (or whatever you call your initiator program).

Colin W.
>
ce (pain n d'ass)
Mar 17 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.