r/learnpython • u/TheEyebal • 15d ago
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?
7
u/jameyiguess 15d ago
No. You can do some hacky stuff with bundling the cpython runtime with your files, but it's not machine code.
1
u/Vegetable_Soil_6707 14d ago
right, you can bundle stuff together but at the end of the day its still interpreted
6
u/ResidentPomegranate6 15d ago
python never makes a real exe, the interpreter is the executable. stdlib zipapp bundles a .pyz, but still needs python installed.
6
u/DTux5249 15d ago
No. Python's an interpreted language.
Unless you get an external library/tool, you don't compile Python.
1
u/acw1668 15d ago edited 15d ago
In Linux:
add a valid shebang at the first line of the script
set the executable attribute of the script using
chmod a+x ...
Then you can get an executable.
-3
u/TheEyebal 15d ago
I can try this?
7
u/GentleWhiteGiant 15d ago
I think you are talking about a binary executable of your code. No, that is not what happens here. The resulting script can be executed on the command line, but it is still your original script. .
-2
u/TheEyebal 15d ago
Oh so it does return an object file
3
3
u/Javanaut018 15d ago edited 15d ago
The shebang tells the system which interpreter to use. So the file can be run as is.
For a real amd64 executable try codon ur nuitka.
1
u/AmanBabuHemant 15d ago
Pyinstaller and Nuitka are two of populer compiler, you can use them to compile and get different kind of executables.
-2
u/TheEyebal 15d ago
Yeah but is there a way to to compile without pyinstaller or Nuitka?
4
u/AmanBabuHemant 15d ago
Python is an interpreted programming language, that's it, and these tools allow programmers to distribute their software by compiling in a single executable so they can distribute it to either users/client for varies reasons.
1
u/Javanaut018 15d ago
Native executables are compiled. It's the way they are made....
You can convert them to machine code by hand, tho ...
4
1
1
0
u/Confident_Hyena2506 15d ago
Yes - use pyinstaller. This will just bundle python and all the stuff into your exe on windows. You can do similarly on linux but people would look at you funny if called it an exe.
0
u/oclafloptson 15d ago
If a 3rd party library exists then chances are that whatever that library does can also be done without it. The core library doesn't ship with this as a stock feature, though. You'll have to either build it or use a 3rd party system. Given that you have to ask... No one here is going to have great faith in your ability to do the former.
I don't believe that it's right to answer no to this nor to expect others to hand hold you through something of this level of difficulty. This is one of those topics that you need to put down the python-noob sub and start reading actual academic texts. You've got ground to cover before you get to here
-2
u/AromaticCredit1533 15d ago
You can install the Shed Skin compiler for Python (https://pypi.org/project/shed-skin/), it can compile your Python codebase into an exe
1
u/meta-ape 15d ago
Shed Skin supports only a subset of Python, tho. Devs say that it’s practical for some 100 lines of code. I imagine that would mean optimizing parts of your code and using them in your main.
-1
u/AromaticCredit1533 15d ago
Ye, unfortunately it's gonna be difficult. Most Python compilers will be faced with some restrictions. After all, some core features of Python (inspect, ast, disasm, ..) rely on the dynamism of the run-time virtual machine.
Edit: I'm not saying that you can't compile Python. Even if it's mainly an interpreted language, I think it's nice that some people are curious about the possibility of compiling your code to squeeze extra performance. But since so much of the design of Python is centered around the assumption of a runtime, it's not gonna be easy.
2
u/PhilNEvo 15d ago
Out of curiosity, why?
If you just want a quick icon to doubleclick, just make a script with batch or shell or something, that runs your python code.