What is the python equivalent to a Java .jar file?

Nathan

Java has the concept of packaging all of the code into a file called a Jar file. Does Python have an equivalent idea? If so, what is it? How do I package the files?

abarnert

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is the Python equivalent of RequestConfig in Java?

From Dev

What is the Python equivalent of Java's UnsupportedOperationException?

From Dev

What is the Java equivalent to Python's reduce function?

From Dev

What is the Python equivalent of Java's UnsupportedOperationException?

From Dev

what is the functionality of dt.jar file in Java?

From Dev

Python equivalent to java.io.File

From Java

What is the equivalent to JAR file META-INF/MANIFEST.MF for a JIMAGE file?

From Dev

What is the equivalent to JAR file META-INF/MANIFEST.MF for a JIMAGE file?

From Dev

What is python equivalent of php file_get_contents("php://input")

From Dev

What is python equivalent of php file_get_contents("php://input")

From Java

What is the Java equivalent for LINQ?

From Dev

What is the 'defer' equivalent for Java

From Dev

What is the equivalent of :: operator in java?

From Dev

what is the equivalent of this in python

From Dev

What is the python equivalent of grep?

From Dev

What is the minimal installation possible in order to run a .jar Java file?

From Dev

What is the storyboard equivalent to an M file

From Dev

What is the Java equivalent of this Scala code?

From Dev

What is the equivalent of javascript setTimeout in Java?

From Dev

What is the equivalent of stringByFoldingWithOptions:locale: in Java?

From Dev

Java 8: What is the equivalent of "UseSplitVerifier"?

From Dev

What is the equivalent of Java Object in Swift?

From Dev

What is the Java equivalent of this Haskell function?

From Dev

What is the equivalent of Java Scanner in Kotlin?

From Dev

What is the equivalent of stringByFoldingWithOptions:locale: in Java?

From Dev

Java equivalent to python's "with"

From Java

An equivalent to Java volatile in Python

From Dev

Equivalent for ? in Java for Python?

From Dev

java equivalent to python for hashing

Related Related

  1. 1

    What is the Python equivalent of RequestConfig in Java?

  2. 2

    What is the Python equivalent of Java's UnsupportedOperationException?

  3. 3

    What is the Java equivalent to Python's reduce function?

  4. 4

    What is the Python equivalent of Java's UnsupportedOperationException?

  5. 5

    what is the functionality of dt.jar file in Java?

  6. 6

    Python equivalent to java.io.File

  7. 7

    What is the equivalent to JAR file META-INF/MANIFEST.MF for a JIMAGE file?

  8. 8

    What is the equivalent to JAR file META-INF/MANIFEST.MF for a JIMAGE file?

  9. 9

    What is python equivalent of php file_get_contents("php://input")

  10. 10

    What is python equivalent of php file_get_contents("php://input")

  11. 11

    What is the Java equivalent for LINQ?

  12. 12

    What is the 'defer' equivalent for Java

  13. 13

    What is the equivalent of :: operator in java?

  14. 14

    what is the equivalent of this in python

  15. 15

    What is the python equivalent of grep?

  16. 16

    What is the minimal installation possible in order to run a .jar Java file?

  17. 17

    What is the storyboard equivalent to an M file

  18. 18

    What is the Java equivalent of this Scala code?

  19. 19

    What is the equivalent of javascript setTimeout in Java?

  20. 20

    What is the equivalent of stringByFoldingWithOptions:locale: in Java?

  21. 21

    Java 8: What is the equivalent of "UseSplitVerifier"?

  22. 22

    What is the equivalent of Java Object in Swift?

  23. 23

    What is the Java equivalent of this Haskell function?

  24. 24

    What is the equivalent of Java Scanner in Kotlin?

  25. 25

    What is the equivalent of stringByFoldingWithOptions:locale: in Java?

  26. 26

    Java equivalent to python's "with"

  27. 27

    An equivalent to Java volatile in Python

  28. 28

    Equivalent for ? in Java for Python?

  29. 29

    java equivalent to python for hashing

HotTag

Archive