简体   繁体   中英

Packing Python code into executables

Situation: Problems importing Python modules due to some compatibility issues with the SBC I am working on. Looking to compiling them into executables.

Problem: I am not very familiar with how the compiling process works.

Question 1: Does compiling a Python code into an executable packs ALL its dependencies into the executable? Ie am I able to run the exact same code on a different computer with no Python installed?

Question 2: Can I import a Python executable as if it is a module and use its functions?

Question 3: Can I pack a Built in Python module into an executable and have it run if Question 2's answer is "yes"?

Python is an interpreted language, and so isn't generally considered to be compiled (there's no out of the box way to create a .exe or elf binary from a batch of code). There are some tools that will essentially bundle your code with a complete python interpreter and let others run it as an executable. See cx-freeze, pyinstaller, py2exe for examples of those.

PyInstaller is pretty easy. For a fairly straightforward bundle, you can just

pip install pyinstaller
pyinstaller your_code_entry_point.py

See their docs for OS specific requirements and details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM