1

I am new to Python having come from a proprietary compiled language (Xojo) that produces self-contained executables.

I understand that Python is an interpreted language. I understand that it requires an interpreter (let’s stick with CPython) and presumably it requires a number of accessory frameworks/C libraries in order to run. What I don’t understand is why is it so hard to create a folder containing the interpreter and all required files and libraries and simply bundle these up with my script to distribute.

I have discovered that there are a bunch of tools that attempt to do this (py2app, cx_freeze, etc) but many of them seem either broken, not maintained or really buggy.

I guess my question is: is there any documentation that describes the exact things I need to bundle with a “Hello World” script to get it running? This seems to be a really straightforward problem to solve but it hasn’t been (which suggests that it is far more complex than I appreciate).

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Garry Pettet
  • 8,096
  • 22
  • 65
  • 103
  • I don't know how you installed python, but as far as I know it comes with a [standard library](https://docs.python.org/3/library/) which is more than enough for common basic stuffs. – Valentino Mar 20 '19 at 20:19

4 Answers4

3

My understanding is that PyInstaller works fine for making a single exe for distribution. But barring packaging tools like that, in general, there isn't an obvious "bare minimum"; the modules don't have documented dependencies, so it's usually best to ship the whole standard library.

Typically, if you need a redistributable version, you use the embedded Python zip redistributable, shipping Python alongside your main application.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
3

The exact list of files/libraries depends on how the python interpreter is built. In windows for example, you can obtain CPython binaries built from Visual Studio, Cygwin and Mingw-w64. They have different dependency of cause. In Linux distributions, python is normally installed by default.

Below is the list of .dll and .exe files that you can find in the official CPython release for windows.

libcrypto-1_1-x64.dll  python.exe   python37.dll  sqlite3.dll
libssl-1_1-x64.dll     pythonw.exe  python3.dll   vcruntime140.dll

The total size of this ZIP file release is only 6.7 MB. So it would be easy to bundle it in your main executable. You can use whatever bundler at hand, not necessary those designed for python. Quoting from the documentation here:

extracting the embedded distribution to a subdirectory of the application installation is sufficient to provide a loadable Python interpreter.

gdlmx
  • 6,479
  • 1
  • 21
  • 39
0

I feel the absolute best way to experience Python for beginners in thonny and an esp32.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 17 '22 at 12:03
-6

A very good way to get started with python is to use Anaconda https://www.anaconda.com/distribution/#download-section - this distribution contains the CPython interpreter and the most commonly used packages. For quite a while you will get along without installing more packages.

To be able to make a simple distributable piece of code just include a requirements.txt along with your code which should list down the packages (and versions) you are using in your code.

More on that here : https://www.idiotinside.com/2015/05/10/python-auto-generate-requirements-txt/

pip freeze generates a superset of all packages in your running environment so you would ideally go with the second smarter option in the link : pipreqs

So, in short along with your code just an additional requirements.txt should be fine using which people can install all required packages as

pip install -r requirements.txt

and they are good to go to run your code.

For advanced scenarios you might want to look up creating virtual environments using conda. What is a conda environment? https://docs.conda.io/projects/conda/en/latest/user-guide/concepts.html#conda-environments

How to create/manage a conda environment https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

All the best in your Python journey!

Nilav Baran Ghosh
  • 1,349
  • 11
  • 18
  • 5
    This is not what the author is asking. This won't bundle an interpreter taht you can just give someone and they can run on their machine without having installed python – juanpa.arrivillaga Mar 20 '19 at 20:25