473,396 Members | 2,129 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,396 software developers and data experts.

distributing python software in jar like fashion

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
20
by: Todd7 | last post by:
I am looking at learning Python, but I would like to know what its strengths and weaknesses are before I invest much time in learning it. My first thought is what is it good for programming,...
0
by: Cliff Wells | last post by:
QOTW: "I find it hard to believe nobody has tried this yet, unless it's the case that those who know how to do it also know that it's actually not possible for some reason..." -- Peter Hansen...
0
by: Josiah Carlson | last post by:
QOTW: "XML with elementtree is what makes me never have think about XML again." -- Istvan Albert "'Plays well with others' was a strong motivator for Python's design, and that often means...
14
by: Phillip Mills | last post by:
I've learned enough of the Python language to be mildly dangerous and have used it in a few personal projects. All my development of commercial (or production) products over the past dozen years...
6
by: Jason | last post by:
A non-python programming friend of mine has said that any programs made with Python must be distributed with, or an alternative link, to the source of the program. Is this true?
5
by: xkenneth | last post by:
Hi All, I'll shortly be distributing a number of python applications that use proprietary. The software is part of a much larger system and it will need to be distributed securely. How can i...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.