Outputed py2exe exe won't run only when signed: ImportError - python

So, I've got a program I made in python 2.6, it ran fine as normal python, and ran fine when made into an exe via py2exe v0.6.9. I used signtool to sign it, having changed nothing else, and it stops working.
When I run the signed exe, I receive an "ImportError: No module named os" from line 1 of my script. I did some digging and found this: http://osdir.com/ml/python.py2exe/2008-04/msg00031.html, which seems to be a very close description of my problem. I manually applied the patch linked to from the py2exe website to my build_exe.py file, though I was running py2exe 0.6.9 instead of 0.6.6, so I tried to take that into account. Still no love.
According to the link, this seems to be a py2exe issue. I don't know though. Any help would be much appreciated. And of course, I'll answer any other questions I can that you have about this. Thanks for the help!

If it's a py2exe issue, maybe give the newer PyInstaller a shot to build your executable. It's in active development, unlike py2exe which apparently hasn't been updated since 2008-11-16.

Related

Need help to understand how the app packed by py2app works

I'm using py2app to package my Python code(Tkinter app), but I'm facing a very strange problem.
I have two Macs, they both have an intel CPU, and they both have the same python version 3.9.8 installed. I packed my App on Mac1 using py2app, it works totally fine. However, on my another Mac2, if I run ./dist/MyApplication.app/Contents/MacOS/MyApplication in the terminal, it works totally fine as well, but if I run ./dist/MyApplication.app directly, it still works, I mean I can still open my App, but some functions will report an error. In addition, if I run the python code on Mac2, it also works totally fine.
I'm sorry I can't provide a reproducible example, but can someone give me a hint or any idea what is going on? How I can debug this issue? Thanks for your help.

How to put .py in .exe? [duplicate]

This question already has answers here:
How can I convert a .py to .exe for Python?
(8 answers)
Closed 2 years ago.
I have Python 3.6 and I did a project in .py that I would like to put in an .exe document ;
How can I do that ? I tried Py2exe but it did not worked due to my python version.
Thanks for your answers.
Traftmine
I faced this problem some times ago, after a lot of googling I found the best solution for me.
Alternatives
Py2Exe: Which is old, the last release on PyPi is on 21 October 2014.
pyInstaller: Is a nice tool, but with some problem that we will see later.
auto-py-to-exe: Use pyInstaller to build the .exe, so suffer the same problem, but has a nice GUI and is intuitive to use.
cx_Freeze: I think the best solution, because it was the only one that works in my case, it is also recommended from python
Investigation
During this time I looked on google and StackOverflow for the best solution, each time that I found something it was out-dated or not well explained/documented, so I studied the official docs.
py2exe
As first try I installed py2exe it seems the best option, also recommended from python, so, give it a try.
All goes fine during the installation process, so I decide to follow the tutorial and get my .exe.
During the step 3 of the tutorial, running setup I received an error, looking on google I found this.
I gave up with py2exe.
auto-py-to-exe && pyInstaller
I have installed auto-py-to-exe and all went good, the program open without problems so I create my .exe file, that works!
The only problem was that, the program works only on my laptop, on all the other machine where I try to execute the antivirus delete it.
Looking on google I found the github repository where I found one issue like the mine, reading it I understand that the problem is pyInstaller.
Looking on the pyInstaller repository I found one issue where one contributors tells to contact the antivirus vendor, so I gave up again.
cx_Freeze
Looking the docs it seems to be overcomplicated realize a simple .exe, so I have studied the documentation and found what I need.
Open you project folder and create inside it a setup.py file with inside:
from sys import executable
from cx_Freeze import setup, Executable
setup(name='programName', version='0.1', description='my fancy description')
Setting up this file require a little bit of study, there are multiple options to set. You can set the option to create a simple .exe or also the create a windows/mac/linux installer.
Once you have your file ready, with the options that you need, just open a shell/terminal/cmd in the directory where the setup.py file is located and execute: python setup.py build
Now in your project folder you will see a folder where inside you can find your .exe file.
You should check out PyInstaller.

Pyinstaller doesn't find crypto. (even in hidden import)

I word with windows 10, python 3.7. (i am also a linux user and to be honest i don't try this with fedora should i try ?)
I use the lastest version of pyinstaller.
When i execute the .exe "ModuleNotFoundError: No module named 'Crypto'"
I double check, Crypto is installed.
(I don't need comment like : don't use crypto because it is not safe)
So, since yesterday, l search online.
At the begining, i didn',t know for the hidden import. So i add it to the in the .spec.
But the error still come up.
Then i try to add the hidden import in command and obviously same error.
I read some other post, and i don't really understand the hook.py stuff. In the github projectof pyinstaller, i find a hook folder. And i don't have it on my computer. Should i have them ?
But soemthing weird came up, i have a file in dist\prepare\libcrypto-1_1.dll
And if this file is really about crypto why the .exe don't use it ?
I try with --onefile and --onefolder doesn't change anything.
if you need something, let me know, i will edit the post.
Thank you for your help, and sorry if the question may sound like stupid.
And sorry for my english ^^
I find the reason, i am a noob
I make a copy of my python direcotry in C:/ and pyinstaller don't find it.^^(because i need it for my IDE)
My bad ^^

PyInstaller app gets caught by SmartScreen

I made a program for people at work that simply takes csvs, converts them, and turns them into a csv that can be read by a different program and I have made the program in Python. Everyone here uses Windows so I originally used py2exe to make an exe and it worked fine for everyone.
Recently, I made some changes to the code to use the newest Python version which py2exe does not support so I used pyinstaller which worked great. However, when I passed it on to a few people at the office to test it, Windows SmartScreen caught it and the Anti-Virus program quarantined it for 3 hours. Obviously this is not ideal. What can I do to not make SmartScreen catch it? And why would py2exe not trigger the same warnings?
SmartScreen show this warning for executables that are not popular and unfortunately Microsoft does't give a certain number of downloads to SmartScreen stop triggering out.

Pygame Distribution - Runtime Error

I am working on a problem with my 2D arcade game programed with Python using the module pygame for 2 days now and I can't find a solution.
The problem is: I want to create a Windows Executable File that is running my program correctly. I already managed to create a .exe file, but I get an error as soon as I start the exe:
Runtime Error!
Path\MyGame.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I tried to create the .exe file with every module that makes it easy to build one, for example cx_freeze, py2exe, pyinstaller. At the end it doesnt matter which one I have used, I got the same error. I already tried to start the .exe file with another PC, it failed. Updated my Microsoft Visual C++ Redistributable, nothing helped.
So the fault must be somewhere in my code. The program is running correctly, but there must be something that prevents me from making a .exe file that works fine.
The code has around 1000 lines, I know it's too much to ask for someone checking the whole code but I hope someone had a similiar problem to this or have some tips why this error is appearing and can help me.
You can find the code here.
The problem is not your code, the problem is how you generate your .exe. Doing that with pygame is a real bitch, but with some hacking and google'ing you can do it.
This should get you started: http://pygame.org/wiki/Pygame2exe
Had similar problems and that one too. Found a way to solve them:
After few weeks (had this problem even before) I'm happy to say that I solved this problem! :)
1st part of my problem (http://i.stack.imgur.com/WpkjR.png):
I solved it by editing setup.py script with adding "excludes" part in it. That resulted in successful making of executable file!
Modified setup.py script:
from distutils.core import setup
import py2exe
setup(windows=['source_static.py'], options={
"py2exe": {
"excludes": ["OpenGL.GL", "Numeric", "copyreg", "itertools.imap", "numpy", "pkg_resources", "queue", "winreg", "pygame.SRCALPHA", "pygame.sdlmain_osx"],
}
}
)
So, if you have similar issues, just put those "missing" modules into this "excludes" line.
2nd part:
After I succeeded in making of executable file, I had next problem: "The application has requested the Runtime to terminate it in unusual way. Please contact...". After days and days of searching and thinking how to solve this another problem, I found a way to do it. I couldn't believe that the problem was so absurd. The problem was in my code, with font definition:
font1 = pygame.font.SysFont(None, 13)
After changing "None" to some system font name (for an example "Arial" (must be a string)), and compiling, I couldn't believe that my .exe file worked!
font1 = pygame.font.SysFont("Arial", 13)
Of course, you can use your own font, but you must specify its path and define it in your program.
So for all of you who are experiencing this issues, try this steps and I hope that you will succeed.
I really hope that this will help you, because I've lost days and weeks trying to solve these problems. I even tried making my .exe file with all versions of python and pygame, with many other .exe builders and setup scripts, but without luck. Besides these problems, I had many other problems before but I found answers to them on stackoverflow.com.
I'm happy that I found a way to solve this problems and to help you if you are faced with the same ones.
Small tips (things I've also done):
1st: update your Microsoft Visual C++ library to the latest one.
2nd: if you have images or fonts similar that your executable program needs, include them to dist folder (where your .exe file has been created).
3rd: when you are making your .exe file, include all needed files to the folder where your setup.py script is (all files and directories that your main script uses).
Used Python 2.7 x64, pygame and py2exe.
Had the same problem, solved it by putting pygame's default font file in the distribution folder. It was used in project, and I'd assumed it would be included in the build automatically.

Categories