Hello.

I don't know if somebody has asked this before, but is there any python equivalent to the Java .jar files? I have read about py2exe, freeze, and module distribution, but it's not what I'm looking for. I need a file that can contain everything in my program (and modules must be compiled, by the way), and that the user can double clic to run. On Windows, I found the pyw extension, and this partially covers my need: I compile everything, then change extensions from pyc to pyw. The problem is that my users want only 1 file pre program instead of having a folder with a lot of modules.

Is there any way to produce an executable file containing everything within it like Java's .jar's?

Edited by G_S: n/a

5
Contributors
11
Replies
12
Views
6 Years
Discussion Span
Last Post by G_S

but is there any python equivalent to the Java .jar files?

Yes .py files.
So think of this jar files will not work if not JRE (Java Runtime Environment) is installed.
To make jar files you need JDK (Java Development Kit)

Py files will not work if python is not installed.
Jus the same as with jar files.

Is there any way to produce an executable file containing everything within it like Java's .jar's?

jar are not executable without java installed,just the same as .py files is not executable without python installed.

Edited by snippsat: n/a

Yes .py files.
So think of this jar files will not work if not JRE (Java Runtime Environment) is installed.
To make jar files you need JDK (Java Development Kit)

Py files will not work if python is not installed.
Jus the same as with jar files.

jar are not executable without java installed,just the same as .py files is not executable without python installed.

Yes, I am aware of the need for an interpreter. But .py files are not comparable with .jar files for 2 reasons:

1. .py files are just plain text files containing the source code, whereas .jar files are compressed files containing everything the program needs to run (this is what I want in python).
2. The files inside a .jar are .class files, which don't contain source code, but rather compiled bytecode.

so the comparison would be:

.py files = .java files (I don't know if you can run these with the JVM without compiling, I think not, but am not sure.)

.pyc files = .class files

.jar files = ? This is what I am asking. Is there some kind of python equivalent?

Sorry if my questions are not clear enough, the part of my brain that manages English is on vacation today.

Take a look at McMillan's installer; looks like archives is what you are looking for.
Disclaimer: I never used it myself.

Take a look at McMillan's installer; looks like archives is what you are looking for.
Disclaimer: I never used it myself.

Thanks. I have also read something about .egg files, but I don't know them. What can you tell me about them? It seems that they are also another sort of compressed file (like .jar's). But, can you run the program without unpacking/installing?

Python egg is the closest jar equivalent. Details here (a little out of date, but easy) and (well not exactly details) here

P.S. I have always considered jar to be the approximate equivalent to 'library' not to 'executable'. Python eggs are also more like a library than an executable (though since Java and Python are interpreted, the boundary blurs)

Edited by griswolf: n/a

From what I read, no, eggs must be unpacked.

From what I read, no, eggs must be unpacked.

If the egg is in the PYTHON_PATH, the Python interpreter will use them without unpacking.

You can put zip file (egg file is also one with aggreed structure, but that is not acceptable for package) to PATH or PYTHONPATH and import package or module normally from Python interpreter without unpacking. .egg file is also zip file with fixed format for scripts and can also be left uncompressed state.

Microsoft Windows XP [versio 5.1.2600]
(C) Copyright 1985 - 2001 Microsoft Corp.

K:\test>dir beautifulsoup.zip
Aseman K nimi on Ysisoft_backup
Aseman sarjanumero on BC0E-2A01

Kansio K:\test

24.03.2011  02:07            36 696 beautifulsoup.zip
1 tiedosto(a)         36 696 tavua
0 kansio(ta)  67 664 384 000 tavua vapaana

K:\test>SET PYTHONPATH=K:\TEST\BEAUTIFULSOUP.zip
K:\test>k:\Python26\python.exe
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import beautifulsoup
Hello
>>> help(beautifulsoup)
Help on package beautifulsoup:

NAME
beautifulsoup

FILE
k:\test\beautifulsoup.zip\beautifulsoup\__init__.py

PACKAGE CONTENTS
BeautifulSoup
BeautifulSoupTests

DATA
__loader__ = <zipimporter object "K:\TEST\BEAUTIFULSOUP.zip">

>>> import beautifulsoup.BeautifulSoup as bs

I have packaged in zip beautifulsoup.zip simple __init__ and compiled version of beautifulsoup in directory named beautifulsoup. print 'Hello' is just to demonstrate using __init__.py main code running when importing.

Edited by pyTony: n/a

Attachments

Thanks for all your input. I just found something: Jython.

Do you think I can make python programs and then generate jar files that are runnable if users have java. Frankly, the problem with python is that there is no compressed filed containing the compiled code and ready to be executed. My users keep complaining that they don't wanna have a lot of .py files lying inside the program folder bu rather a single file they can put in their USB stick and take (and run) anywhere (Anywhere here means Windows and Linux platforms with the proper interpreter, of course).

So, what's this Jython thing? After reading I understood that this is a different interpreter that can compile python source into java bytecode, am I right?

Maybe this is what you think:

Standalone mode

The standalone option does no caching and so avoids the startup overhead (most likely at the cost of some speed in calling Java classes, but I have not profiled it)

You can try it out by running the installer:

$java -jar jython_installer-2.5.2.jar then when you come to the "Installation type" page, select "Standalone". The installation will generate a jython.jar with the Python standard library (/Lib) files included, which can be run as:$ java -jar jython.jar

Of course you can run scripts just by calling them as you might expect:

\$ java -jar jython.jar script.py

Or, add this file to the classpath of your application.

Edited by pyTony: n/a

Maybe this is what you think:
From: http://wiki.python.org/jython/InstallationInstructions#standalone-mode

I tried it already. If I'm not mistaken this thing is another interpreter for python. But it runs java bytecode instead. So if you compile, it generates a .class file instead of a .pyc. I presume I can generate .jar files too.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.