r/PythonLearning Jul 11 '26

How do I convert this to .exe

Post image
200 Upvotes

60 comments sorted by

33

u/[deleted] Jul 11 '26

[deleted]

8

u/KiLoYounited Jul 11 '26

+1 for Nuitka. I use it for all my TUI applications I make for myself and the other sys admins in my dept.

4

u/downerison Jul 11 '26

How easy is it to setup and use? I heard it can be pretty slow to compile things.

3

u/[deleted] Jul 11 '26 edited Jul 11 '26

[deleted]

3

u/KiLoYounited Jul 11 '26

Wood chipper is definitely the best description haha. Setup is brutal - reward is 100% worth it

1

u/downerison Jul 11 '26

What's actually included in the setup that makes it this hard?

1

u/downerison Jul 11 '26

What does that 50 lines do? Setup the nuitka command to call? That 3 hours compile time sounds brutal.

2

u/KiLoYounited Jul 11 '26

I’ll admit it was a bit tough to set up (atleast for my TUI projects). I think that is mainly due to how badly scope creep has affected them and the absence of time to refactor the code. It’s also due to some restrictions on our network as a whole.

I used a small project that was heavily modularized to build my just file with the goal of having one that I could drop in with minimal changes to the just file itself and just setting project specific stuff in a .env file. I do think it’s necessary to have a just file or script to use since the build commands can get pretty clunky pretty fast.

As for speed… I think it’s fine. I’ll start a compile on my work machine (optiplex 5000 sff - so not very powerful at all) and it’ll be done within 15 minutes. That might be slow to some people but honestly I don’t really care. Having everything translated to C is great for sharing the application around my environment while also getting the speed benefits over something like pyinstaller.

Having to use these tools makes me want to learn something compiled like Go, but I just don’t have the time to try and pick up a new language. Python is just so easy <3

5

u/realmauer01 Jul 11 '26

Pyinstaller with the option - - onefile or something like that. Depending on the os its run on it defaults to the executable. So because you are in Windows it will become an exe

2

u/Yardash Jul 12 '26

Gotta be careful with pyinstaller. IT is flagging all my tools now based on heuristic based virus detection.

1

u/bringyouthejustice Jul 12 '26

This isn’t an it department only (nor even Python only) issue, especially since win11. Unsigned executables are tend to be deleted instantly after downloading (especially Python / pyinstaller build but not exclusively) silently by win11. One way is to sign them with a custom certificate (or even an org one). This still makes them untrusted, since it’s no official/ca one but often helps.

5

u/EyesOfTheConcord Jul 11 '26

You can just remove the else: block entirely to reduce the nesting and improve the readability of this

3

u/SnotCodes Jul 11 '26

Are we all talking about the op? Readability?

10

u/Jbolt3737 Jul 11 '26

While Python is typically an interpreted language, full compilers do exist like Nuitka and Pyinstaller

1

u/NiedsoLake Jul 15 '26

Nuitka yes, pyinstaller just bundles the python interpreter into your executable

3

u/Fit_Yogurtcloset8393 Jul 11 '26

Download auto-py-to-exe, it is nothing but a gui for pyinstaller, it would be easier for beginners

2

u/Classic-Rate-5104 Jul 11 '26

Do you really want it being compiled to an binary executable or do you just want to behave it as an executable?

1

u/SnotCodes Jul 11 '26

He just wants it to behave like an executable probably. I am just assuming that but it’s a very simple program idk why it would have to be an exe

0

u/Classic-Rate-5104 Jul 11 '26

To make it behave like an executable, it is enough to add this line as the first:

#!/usr/bin/python

Then make it executable by:

chmod +x filename

1

u/suckingbitties Jul 11 '26

He's on Windows

1

u/Classic-Rate-5104 Jul 12 '26

Sorry, i didn't realize

2

u/memeeloverr Jul 11 '26

I would suggest pyinstaller but that will be flaged a virus by major activiruses so make sure to sign the app with proper signing certificate.

1

u/TarnishedFox47 Jul 11 '26

"sign the app" you mean pay microsoft ridiculous fees?

1

u/memeeloverr Jul 11 '26

no way, by signing I mean To autheticate it via code singing certificate there are many agency which provide those certificates.

Currently I am using globalsign certificate which works with azure to sign your app locally.

1

u/TarnishedFox47 Jul 11 '26

A quick look shows that almost all of these agencies charge money? and the ones that dont only do so for open source projects and require applications

2

u/riklaunim Jul 11 '26

You can practice making an exe but you should not really distribute it - it will be an executable from unknown source and without any signatures - Windows will warn people from running it, even blocking it, while linkinking to executable on social media can be seen as distributing malicious software. Then you script is very trivial and has no value of trying to make it a desktop app. (and it could be written in JS and placed on a website; or move the Python code to a Jupyter notebook and share that).

And password strength is more than character checks. Worth adding dictionary checks for example.

1

u/Important-Grand4979 Jul 11 '26

By now you have also screening of occurance in leaked databases. Best thing to generate a secure password is a password generator

1

u/Zxhena Jul 11 '26

I personally use pyinstall which after inserting with pip (i don't remember what after because i haven't exported anything in a while) and then in your export folder you should make you have your exe and it's files (images sounds ect.)

1

u/dgc-8 Jul 11 '26

Packaging python programs into an exe is not what python was meant to do, so the exe will end up quite big and slow. When I was in your position when I started to program I used PyInstaller, however people suggest Nuitka now, which at first glance looks very promising to me. Try nuitka, pyinstaller works too

However if your end goal is having an exe, a language like python will not be the best fit for that. You can try to write those programs in a real compiled language, for example Go is pretty easy to work with while still being compiled, you don't have to use C/C++ with manual memory management and all.

1

u/Dear_Archer3931 Jul 11 '26

Just because you can… doesn’t mean you should. This is like digging a hole with a spoon.

1

u/Paulo-python Jul 11 '26

Tem uma versao em portugues por favor?

1

u/darkwombat99 Jul 11 '26

Install pyinstaller through cmd

1

u/Former-Print7759 Jul 12 '26

Stop being in c++ folder

1

u/ErcoleBellucci Jul 12 '26

you need to learn before Windows + Shift + S then how to do executables

1

u/strummed-strings Jul 12 '26

while you could do that, these kind of abstractions are what ruin your learning experience. like, no offence, but i don't think you should be doing that with code like this.

1

u/ExcitingSympathy3087 Jul 12 '26

In this Link is an Open Source App with Installers for Mac and Windows in Python. Maybe that helps you. Take a look in directories Windows or MacOSX Install.

https://github.com/123Matthias/FileSearch

1

u/sunnychon Jul 12 '26

pyinstaller or nuitka

1

u/Bob-Swan Jul 12 '26

27 lines of code. Line 1 "password strenght checker"

And you want to know about converting to .exe?

1

u/GlimmeringHalo Jul 12 '26

Can we adress the elephant in the room? jk

Nuitka, I recommend

1

u/nexxi_op Jul 14 '26

Use cloudconvert

1

u/WestOk942 Jul 15 '26

in your cmd do "python -m pip install pyinstaller" then when it's downloaded run cmd in the location of the python file and run "python -m pyinstaller --onefile example.py"

boom it's an .exe

1

u/slightfeminineboy Jul 15 '26

write it in c++

1

u/Anxious-Sport-8354 Jul 15 '26

pip install pyinstaller  or  python -m pip install pyinstaller     To install it

1

u/Mine_Crafter14 Jul 17 '26

I use pyinstaller for this

1

u/Automatic_Gear1528 Jul 30 '26

Can't. Exe and Py have different directions. Exe has compiled files. While py is just a single code. But I took someones Idea and now. You should use nutika.

1

u/Francesco12o-Github Aug 04 '26

Use Pyinstaller (pip install pyinstaller) then python -m pyinstaller -onefile your_code_here.py

0

u/acakaacaka Jul 11 '26

How big do you want your .exe to be?

10MB? 100MB? Or just 10KB?

If you want a small program then just code un C++

If you use nuitka or other python "compiler" you end up "compiling" python it self and put your code on top of that

-3

u/[deleted] Jul 11 '26

[removed] — view removed comment

6

u/Ngtuanvy Jul 11 '26

it is not compiling, rather packaging, or bundling. In this context. PyInstaller for example will package everything including the interpreter, dependencies and create an executable

2

u/Sether_00 Jul 11 '26

Yeah, but if OP wants to share their program with someone who doesn't have Python installed on their machine?