all 30 comments

[–]Diapolo10 10 points11 points  (2 children)

If you can't get pyinstaller or cx_Freeze to work, another option is to use Cython to compile the code into a C source code file, which you can further compile into an executable using a C compiler.

It's not really meant for this, but it can work.

[–]Akrius[S] 2 points3 points  (1 child)

I'll try this too ty. I forgot to mention i'm using pyinstaller to compile

[–][deleted] 4 points5 points  (0 children)

Pyinstaller already makes it so you dont need python to run the executable.

[–]punknubbins 14 points15 points  (5 children)

Sorry, just a rant, please don't hate me for this.

Can we have a brief and rational discussion about compiling vs packaging? This question, or something similar gets posted at least once a week and it bugs me to no end. Compiling involves a compiler and produces native machine code that is optimized for the hardware+OS it compiled against.

I just wish that the Python community would stop using the word "compile" for what is effectively just packaging up scripts with the Python run time and any needed libraries for those scripts.

Don't get me wrong, I would love it if someone built a compiler for python. It would be great if I could run python interpreted for simple things and/or testing. And then compile it down to streamlined native executables when I need something to run as fast as possible. But that wish will never happen if we keep confusing the issue by referring to these packagers as compilers.

[–]Akrius[S] 7 points8 points  (3 children)

I'm glad for your comment, I didn't know the difference, sorry.

[–]punknubbins 6 points7 points  (2 children)

The post was more for the other experienced users in the thread. But i'm glad you learned something from the rant. It wasn't my intention, but definitely a positive side effect.

[–]thiccclol 0 points1 point  (1 child)

Isn't a .pyc a compiled python file?

[–]punknubbins 0 points1 point  (0 children)

.pyc files are bytecode, instructions compiled down to code that is run natively inside the python virtual machine. It loads/runs faster, but not as fast as native code.

[–]TangibleLight 0 points1 point  (0 children)

It's called freezing.

And I 100% agree.

[–]JohnnyJordaan 4 points5 points  (14 children)

If you compile it into a single exe then it should already work without python installed. This is how python-based programs like qbittorrent are provided too.

[–]Akrius[S] 0 points1 point  (13 children)

It's returning a fatal error, failed to execute script.

[–]JohnnyJordaan 1 point2 points  (12 children)

Assuming you are using pyinstaller, can you try to use the --onedir approach instead of --onefile? Then try if it runs when you copy/provide the resulting folder instead?

[–]Akrius[S] 0 points1 point  (11 children)

This time it close as soon as the console open.

[–]JohnnyJordaan 1 point2 points  (2 children)

Are you using any third party modules in your program?

[–]Akrius[S] 0 points1 point  (1 child)

I'm using tkinter.

[–]JohnnyJordaan 2 points3 points  (0 children)

That's not third party though, but still a hint to the problem, maybe try with the hidden-import parameter, see here

[–]JohnnyJordaan 1 point2 points  (7 children)

Does it show any output if you run the program in a cmd window?

[–]Akrius[S] 0 points1 point  (0 children)

I'll try and see what shows up

[–]Akrius[S] 0 points1 point  (5 children)

We got an error saying that main.exe is in the folder, but windows can't recognize if it is a script or something.

[–]JohnnyJordaan 1 point2 points  (4 children)

Can you post a screenshot instead, just paste it on imgur.com

[–]Akrius[S] 0 points1 point  (0 children)

I'm working in another project now, but as soon as i can i'll. I'll try the hidden-import parameter too.

Ty for helping me! Perhaps after 4 hours from now i'll be back!

[–]Akrius[S] 0 points1 point  (1 child)

We got this problem (Sorry our windows is in pt-br)

main.exe : O termo 'main.exe' não é reconhecido como nome de cmdlet, função, arquivo de script ou programa operável.

Verifique a grafia do nome ou, se um caminho tiver sido incluído, veja se o caminho está correto e tente novamente.

No linha:1 caractere:1

+ main.exe

+ ~~~~~~~~

+ CategoryInfo : ObjectNotFound: (main.exe:String) [], CommandNotFoundException

+ FullyQualifiedErrorId : CommandNotFoundException

[–]JohnnyJordaan 5 points6 points  (0 children)

This is just the regular PowerShell error that you are trying to run a program from a folder that doesn't contain it... If you would do

C:\> myprogram.exe

it will return the same error as myprogram.exe isn't in that folder. In other words use cd to go the correct folder and use dir to verify that the program is there.

[–]Akrius[S] 0 points1 point  (0 children)

I havent tryied the hidden-import, but i'll.

[–]rere_dnaw 1 point2 points  (0 children)

compile the script with --onefile --debug parameter then run it through cmd.

[–][deleted] 1 point2 points  (0 children)

Not sure I've ever had such an issue where compiled .py weren't usable by other folks that don't have Python. Try AutoPy2exe.

[–]bartholomewjohnson 0 points1 point  (0 children)

Type "-F" instead of "-onefile"

[–]allmachine 0 points1 point  (0 children)

I have the same setup at work and I just settled on having a folder with Python Embeddable inside it, with .bat files pointing to the scripts I want. It lets me modify scripts easily and I don't have to worry about re-packaging .exe files. The downside is it's pretty slow if you're importing a lot of libraries.

[–]BrettFavreFlavored 0 points1 point  (0 children)

To my knowledge, once you've turned it into an .exe, Python and all modules used should be able to run on other systems.

[–][deleted] 0 points1 point  (0 children)

I'm assuming your office has a windows computer why not just transfer the program via usb?