Python doesn't have any exact equivalent to a .jar file.

There are many differences, and without knowing exactly what you want to do, it's hard to explain how to do it. But the Python Packaging User Guide does a pretty good job of explaining just about everything relevant.

Here are some of the major differences.


A .jar file is a compiled collection of classes that can be dropped into your application, or installed anywhere on your CLASSPATH.

In Python:

  • A .py (or .pyc) module can be dropped into your application, or installed anywhere on your sys.path, and it can be imported and used.
  • A directory full of modules can be treated the same way; it becomes a package (or, if it doesn't contain an __init__.py, it merges with other directories of the same name elsewhere on sys.path into a single package).
  • A .zip archive containing any number of modules and packages can be stored anywhere, and its path added to your sys.path (e.g., at runtime or via PYTHONPATH) and all of its contents become importable.

Most commonly, you want things to be installed into a system, user, or virtualenv site-packages directory. The recommended way to do that is to create a pip-compatible package distribution; people then install it (and possibly automatically download it from PyPI or a private repo) via pip.

pip does a lot more than that, however. It also allows you to manage dependencies between packages. So ideally, instead of listing a bunch of prereqs that someone has to go download and install manually, you just make them dependencies, and someone just has to pip install your-library. And it keeps track of the state of your site-packages, so you can uninstall or upgrade a package without having to track down the specific files.


Meanwhile, in Java, most .jar files are cross-platform; build once, run anywhere. A few packages have JNI native code and can't be used this way, but it's not the norm.

In Python, many packages have C extensions that have to be compiled for each platform, and even pure-Python packages often need to do some install-time configuration. And meanwhile, "compiling" pure Python doesn't do anything that can't be done just as well at runtime. So in Python, you generally distribute source packages, not compiled packages.

However, .wheel is a binary package format. You can pip wheel to build binary packages for different targets from the source package; then, if someone tries to pip install your package, if there's a wheel for his system, that will be downloaded and installed.

Answer from abarnert on Stack Overflow
Top answer
1 of 4
38

Python doesn't have any exact equivalent to a .jar file.

There are many differences, and without knowing exactly what you want to do, it's hard to explain how to do it. But the Python Packaging User Guide does a pretty good job of explaining just about everything relevant.

Here are some of the major differences.


A .jar file is a compiled collection of classes that can be dropped into your application, or installed anywhere on your CLASSPATH.

In Python:

  • A .py (or .pyc) module can be dropped into your application, or installed anywhere on your sys.path, and it can be imported and used.
  • A directory full of modules can be treated the same way; it becomes a package (or, if it doesn't contain an __init__.py, it merges with other directories of the same name elsewhere on sys.path into a single package).
  • A .zip archive containing any number of modules and packages can be stored anywhere, and its path added to your sys.path (e.g., at runtime or via PYTHONPATH) and all of its contents become importable.

Most commonly, you want things to be installed into a system, user, or virtualenv site-packages directory. The recommended way to do that is to create a pip-compatible package distribution; people then install it (and possibly automatically download it from PyPI or a private repo) via pip.

pip does a lot more than that, however. It also allows you to manage dependencies between packages. So ideally, instead of listing a bunch of prereqs that someone has to go download and install manually, you just make them dependencies, and someone just has to pip install your-library. And it keeps track of the state of your site-packages, so you can uninstall or upgrade a package without having to track down the specific files.


Meanwhile, in Java, most .jar files are cross-platform; build once, run anywhere. A few packages have JNI native code and can't be used this way, but it's not the norm.

In Python, many packages have C extensions that have to be compiled for each platform, and even pure-Python packages often need to do some install-time configuration. And meanwhile, "compiling" pure Python doesn't do anything that can't be done just as well at runtime. So in Python, you generally distribute source packages, not compiled packages.

However, .wheel is a binary package format. You can pip wheel to build binary packages for different targets from the source package; then, if someone tries to pip install your package, if there's a wheel for his system, that will be downloaded and installed.

2 of 4
7

Easy Install from setup_tools defines the .egg format for deploying Python libraries or applications. While similar to JAR, it is nowhere spread as universally as JARs in Java world. Many people just deploy the .py files.

A newer format, intended to supersede eggs, is wheel.

🌐
PyPI
pypi.org › project › jars
Client Challenge
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Klukas
jeff.klukas.net › home › lib.jar java library? python package? both?
lib.jar: Java library? Python package? Both? - Jeff Klukas
July 26, 2018 - The Java distribution comes with a jar executable that can be used for looking inside or extracting a jar, but it’s not strictly necessary. unzip mylib.jar works just as well as jar xf mylib.jar. The usual method for installing a Python library is via pip which can handle downloading and installing a lib to an appropriate place on the filesystem such that the Python interpreter’s import mechanism will find it.
🌐
Coderanch
coderanch.com › t › 769876 › languages › run-Python-dependency-libraries-running
Way to run Python with dependency libraries like running Java by making jar of them using pom.xml (Jython/Python forum at Coderanch)
February 4, 2023 - But is it correct to say that the closest thing in python like Java jar is wheel ? ... Tim Holloway wrote: Install time, therefore is the time at which the system operator will use the OS package manager and/or pip to download an installable package to the system that the app will run on.
🌐
CodeBurst
codeburst.io › how-to-package-java-projects-in-python-tar-files-b9b3ff7a0627
How to Package Java Projects in Python Tar files | by Kartik Khare | codeburst
March 2, 2021 - You can do that by simply mentioning ...egration-lib-1.0.0.tar.gz . You can now install this python package using the command · pip install dist/java-integration-lib-1.0.0.tar.gz...
🌐
Medium
medium.com › @darioros › python-notes-from-java-developers-shared-libraries-7cc083d39ea2
Python modules like Jar libraries | by Dario Rossi | Medium
August 4, 2019 - Now it’s possible to install a library in development mode. See more details here: ... $ pip freeze# Editable install with no version control (ptwo==0.0.1) -e /Users/dariorossi/cave/python/packaging/pkga
🌐
SSEC
ssec.wisc.edu › ~tomw › visadtutor › compile.html
Compiling your Python code with jythonc
comp --core --jar mything.jar mything.py The documentation on jythonc can be found here and has all the details of the options.
Find elsewhere
🌐
Appjar
appjar.info › Install
Installation - appJar
NB. If you're on linux/Mac you might need to use sudo: sudo pip3 install appjar · # import the appJar library from appJar import gui · If you can't/don't want to install using pip, simply:
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 355378 › is-there-something-like-a-jar-file
python - Is there something like a jar file? [SOLVED] | DaniWeb
March 24, 2011 - Users can run it with python app.pyz, and on Windows you can associate .pyz so a double-click launches it. You can also bundle third-party deps into the archive (install them into a build directory first), similar to a fat JAR. See zipapp docs. If your users must run without installing Python, use a one-file packager that embeds the interpreter.
🌐
Data Science Learner
datasciencelearner.com › python › how-to-call-jar-file-using-python
How to Call Jar File Using Python? - Python Tutorial Data Science Learner
October 27, 2022 - This article " How to call jar file using Python " will brief you on two different ways in Python to call jar externally (os.system and subprocess.call) .
🌐
Readthedocs
voc.readthedocs.io › en › latest › background › install.html
Installation — VOC 0.1.6 documentation - Read the Docs
> py -3 -m venv env > env\Scripts\activate.bat > cd voc > pip install -e . ... This should create a dist/python-java-support.jar file. This JAR file is a support library that implements Python-like behavior and provides the Python standard library for the Java environment.
🌐
Medium
medium.com › @randy-huang › dataproc-add-jar-package-to-your-cluster-while-creating-a-cluster-582529fab577
Dataproc — add jar/package to your cluster while creating a cluster | by Randy | Medium
July 12, 2022 - Add multiple jar files and multiple Python packages · MY_CLUSTER="cluster-myname" REGION="us-west1" INITIAL_SCRIPT="gs://goog-dataproc-initialization-actions-us-west1/python/pip-install.sh" $gcloud dataproc clusters create $MY_CLUSTER \ --region $REGION \ --properties #^#dataproc:conda.packages='pytorch==1.7.1,tokenizers==0.10.1'#dataproc:pip.packages='google-cloud-storage==1.38.0,datasets==1.5.0'#spark:spark.jars="gs://spark-lib/bigquery/spark-bigquery-latest_2.12.jar,gs://my-lib-project/trevni-3.1.1-SNAPSHOT.jar"
🌐
Jython
jython.org › installation.html
Installation | Jython
After downloading it, either double ... the -jar option ... This will start the regular GUI installer on most systems, or a console installer on headless systems. To force the installer to work in headless mode invoke the installer as: ... The installer will then walk through a similar set of steps in graphical or console mode: showing the license, selecting an install directory and JVM and actually copying Jython to the file ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › fabric › data-engineering › library-management
Manage Apache Spark libraries - Microsoft Fabric | Microsoft Learn
2 weeks ago - After you upload a library, you can drag and drop it into a code cell to automatically generate the install command. Or you can run the following command: # install the .whl through pip command from the notebook built-in folder %pip install ...
🌐
IBM
ibm.com › docs › SSHGWL_1.2.3 › local › admin-libraries.html
Manage packages as a Watson Studio Local administrator
A Watson Studio Local administrator can install Python or R packages in global directories. These packages are available to all users on the cluster.
🌐
Python Packaging
packaging.python.org › tutorials › installing-packages
Installing Packages — Python Packaging User Guide
python3 -m pip install --no-index --find-links=file:///local/dir/ SomeProject python3 -m pip install --no-index --find-links=/local/dir/ SomeProject python3 -m pip install --no-index --find-links=relative/dir/ SomeProject Windows
🌐
GitHub
github.com › combust › mleap › issues › 487
Where are the mleap jar files installed when using pip install mleap? · Issue #487 · combust/mleap
February 14, 2019 - I searched under site_packages in my environment and I can see mleap and its python files however can't find any jar files so I can add them to the library path.