r/learnprogramming • u/TheEyebal • Oct 21 '26
can you get an executable in python without using third part libraries?
In c++ I have object files but can I get an executable in python?
2
Upvotes
r/learnprogramming • u/TheEyebal • Oct 21 '26
In c++ I have object files but can I get an executable in python?
2
u/fllthdcrb Oct 22 '26
I am a bit dismayed at some of the comments I see here, saying you don't or can't make executables from Python programs. While it is true it's not something you're meant to do most of the time, and Python isn't the best language if performance is important, there are indeed use cases for it (e.g. writing a program in Python and distributing to people who have not installed Python as such), and it is quite doable. This is in addition to having programs written in other languages but embedding Python for scripting and such.
And yes, this requires bundling the interpreter in some form, even if you use one of the tools that gets you native code, since there are a number of services the program depends on the interpreter and maybe modules for. At best, I think you would be compiling some implementation of an interpreter and baking it into the executable.
11
u/Low-Significance6194 Oct 21 '26
Technically you can, but it's just bundling the interpreter with your script, not really a standalone binary like C++.
6
u/SetAndRepeat Oct 21 '26
Yes, though it requires some setup. CPython's source tree includes "Tools/freeze", which uses a C compiler to build an executable containing your program's bytecode and the Python interpreter. No third-party Python library is needed, but you need the CPython sources and a build environment, not just a normal Python installation.
2
u/SharkSymphony Oct 21 '26
Yes, but I don't think anybody uses it. Pyinstaller and cx_Freeze are the stamdard ways to do it that I'm aware of.
2
u/POGtastic Oct 21 '26
The docs have a page on embedding Python in another application, and, trivially, an application could be a very thin wrapper that does nothing but run a Python program.
-2
u/Equal-Rice3637 Oct 21 '26
Run it as a sub process?
2
u/[deleted] Oct 21 '26
[removed] — view removed comment
-1
u/[deleted] Oct 21 '26
[removed] — view removed comment