Hey guys I created a program, used pyinstaller --onedir 'name' and created the exe.
Now I am having an issue while it works perfectly on my computer (windows 7) when I took the dist folder to a windows 10 machine the cmd window started and closed at once without running and without giving out an error message (or it was fast enough that I could not see it).
Is this an issue with windows 10 or did I do anything wrong when compiling to exe?
What happens is that probably your dist directory requires different dlls, probably some system ones that you need to add them into your one directory executable so that everything is linked correctly.
One way to find the missing dependencies of your exe is to use Processor monitor https://learn.microsoft.com/en-us/sysinternals/downloads/procmon in your Win 10. You see the traces of your process and then you investigate.
One other way is to install Process explorer https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer and check the dlls that did load to see where it stops.
There is also https://dependencywalker.com/ which is really powerful, but when I used it in similar scenarios, it didn't help me that much.
Also have a look at the possible errors that pyinstaller might raise, even the slightest warning can be helpful.
One other concern would be the machine you are using: let's say you have a generated process which contains dlls with 64 bits that you are trying to run in a machine with 32 bits.
I hope this helps.
Related
I made a Python script that mails a Windows directory as zip to me. I added a scheduler using sched module that repeats this every hour.
I was attempting to make a simple sync application for personal use that starts at Windows Startup.
I converted it to exe using pyinstaller --onefile argument and it worked flawlessly.
But after a couple of days, Windows defender (Windows Security Centre of Windows 10) detected it as a Trojan.
This issue is not limited to Windows Security Centre, A quick scan on Virus Total says 4 antivirus detects it as Trojan.
What brings the Antiviruses to think this? I don't think sharing the code is any use as proper details have already been given, but still, a comment would make me do it.
Most antiviruses will mark this as a Win32.Trojan.whatever because it will detect that the EXE executable is simply extracting binary code. This works just like a ZIP, where Gmail blocks ZIPs.
To summarize, this is like a self extracting EXE, so kind of like an installer. For example, when you execute an installer, you sometimes get the User Account Control window, which is detected when the system is trying to grant advanced permissions for the EXE.
It must be a something else that made Windows Defender suddenly think it's bad. Maybe it's an update, try updating it.
This question was asked once before, but seeing as that discussion was five years ago and I've tried some of its recommendations without success, I'm asking it again, albeit in a slightly different context.
I installed the topydo Python app, and it runs fine from the terminal (i.e., at the command prompt, entering "topydo," "topydo prompt," or "topydo columns" all work as they should). But then I tried two solutions suggested on the previously cited thread (Automator and AppleScript solutions), and neither of them worked. It appears that the OS can't find the topydo executable. I even tried using an absolute path, /Library/Frameworks/Python.framework/Versions/3.6/bin/topydo,
but had no luck.
Any ideas how to create a clickable icon that will launch topydo from the Mac's GUI? (This is on OS X 10.10.5, Yosemite.) Having to open a terminal window every time I want to run the program is a real drag.
(BTW, while nosing around to deal with this, I noticed that /Library/Frameworks/Python.frameworks/Versions has a subdirectory named "Current," but "Current" doesn't have the newly installed topydo executable. Instead, topydo is in the 3.6 subdirectory. I assume this is because the Mac ships with Python 2.7, which is used by the system. Assuming the "Current" directory is defined via a symlink, would redefining it to point to the 3.6 subdirectory instead of to the 2.7 subdirectory be likely to cause a problem?
EDIT: I found out that the error is that the resources couldn't be opened. Copying the directory into the folder where the .exe is didn't fix it. I tried removing the resources from the .spec file and the size of the .exe file is now 9 MB as opposed to 52 MB so I'm pretty sure the resources are included, but somehow they can't seem to be opened by the .exe. In case anything is wrong with it, This is my .spec file - I only modified the Tree thing to include the resources, the .exe filename and icon.
In other words, the question now is: Why can't the exe find my game resources, and what do I have to do to fix that? Also, I realised my resources folder has two subfolders - does that mean I have to go about writing the Tree differently?
I've made a game in Python (using Pygame, too) and want to make a single executable file so I can distribute it. PyInstaller seemed perfect for that, and eventually, after a while of searching, I found out how to get it working in this guide. After I tweaked my code to get step 2 working I created the .spec file, added the directory with the resources to it (as in step 5, and including the font file), copied it to the same folder the .spec file was in and finally I ran
build.py game.spec
and I found the .exe file exactly where it was supposed to be. However, when I open it, it just closes again after a few seconds, and I think it's just before the main menu shows up. I'm not really sure it's a font screw-up again though because I made sure to include it in the resources as well...
Unfortunately, searching for a solution on the web didn't help me at all, especially because half the links to the project are broken now.
If anyone knows what's gone wrong here (or needs more details) please let me know.
Details:
Python version: 2.7.7 32 bit
Pygame version: 1.9.3 32 bit
PyInstaller version: 1.5 32 bit
System: Windows 8.1 64 bit (the 32 bit programs have all worked fine so far though)
Try to open command prompt and drag exe into it and press enter, that way you will catch the error (if there is any) and then update your question, more info == more help.
I never used pyinstaller so I can't really help you on that.
Also I suggest you to try py2exe, it worked nicely with pygame (at least for me) and later you can make setup with NSIS or Inno.
Edit:
If the .exe can't permanently save the highscores (as you said in comment below) try running exe as admin, it might be just matter of write privileges , or maybe it is your antivirus who doesn't allow it to write (sandbox at Avast, unknown/rare file at Norton).
I didn't find out what the problem was but I did manage to get it working. I started by installing the newer version of PyInstaller (2.1) with pip and completing the same steps again, but this time in the Scripts directory and running pyi-makespec and pyi-build instead of makespec.py and build.py because that's how the new version works, I guess. At first it would still complain about the resources being missing unless I ran it from cmd, but I think that was actually because I forgot step 5 (Tree in the makespec file). For some reason now the .exe can't permanently save the highscores, but apart from that it's working perfectly.
I am "compiling" my Python application for Windows with PyInstaller 2.1. I initially tried using onefile mode, but onefile takes a long time to startup (decompressing wx and matplotlib). With the onedir mode it's pretty fast (only a little bit slower than native python).
So I want to use onedir mode for faster startup times, but for the end-user it's difficult to find the actual *.exe file inside the huge amount of files located in the main directory (there are 98 files including the actual executable and it's manifest).
I want to make sure a non tech-savvy user can easily "double-click" the executable and work with this program (ease and portability) without a long disclaimer to "just ignore" the 97 other files there.
Is it possible to move all those "distracting" files into a subfolder? Or are there other ways to make it easy for the end-user to run this program?
maybe you could use onedir. The resulting folder you can put anywhere and create a shortcut to the user where it is more comfortable.
Easiest way to reduce the number of files created in --onedir mode would be to create a virtual environment and install only the necessary modules.
You could use some software to pack it into a one-file installer, such as Inno setup.
You could also try to delete some files one by one (if the executable fails just undelete it). I figured out that almost half of the files can be deleted with the executable working fine.
Download Inno Setup from here.
I have an EXE that I built that I am trying to have installed in the Program Files (x86) folder on Win7 machines. There is really interesting behavior going on. The program has a gui-we used wx-Python and XRC to handle the interface. we include an XRC folder in the distribution. The program uses getcwd() to locate itself and find the xrc folder. However, and this is really interesting-it all works fine when I place the program in Program Files. When I place the program in the Program Files x86 folder I get a message that indicates to me that it can't find the xrc folder.
Let me be clear this application runs fine on an XP machine in Program Files and on a Vista Machine as well as a Win7 machine in Program Files
Now what else is interesting is if I double click the exe in the Program Files (x86) folder it runs fine but when I try to run it off of the short cut added to the start/program menus it does not run correctly. That is where I get the error message that suggests the program is not finding the xrc folder. I also moved the program to a folder on the desktop, and at the root and in every other location it starts and runs fine. Thus I am confident that my code to point to the xrc folder is fine.
So back to the question. When programs are running from the x86 folder is something happening that causes the path references to get screwy? More importantly is it fixable?
One final note- To be as certain as possible that the problem relates to the path to the xrc folder I deleted the xrc folder from two instances of the application and I get the same error message that I received when the program was installed in the x86 folder.
Just for clarification the only time the program will not run is when I use the shortcut on the start menu and the exe and all of the parts are saved in the Program Files (x86) folder
Plasticsabers answerreally helped me understand the problem and I was able to fix it. This is not a Vista verus XP issue it is a 32 bit OS versus 64 bit issue.
I need to run on 64 bit XP and 32 bit Win7.
According to this note, the Program Files (x86) folder is specifically intended for 32-bit program files, as opposed to the Program Files folder, which is intended for 64-bit programs.
But in order for a 32-bit program to pretend that it's on a 32-bit machine, the name of the working directory has to be returned as 'Program Files,' because that's what it would be on a 32-bit machine. This is what you're seeing when you ask Windows for the working directory with getcwd(). Since your program is trying to use that directory name in a path, and that's not actually the path to the file on the real, 64-bit machine, it breaks.
Looking at the WOW64 docs, I suspect the reason it only breaks when launched from the start menu is, that's an instance of a 64-bit process creating a 32-bit process, which causes the system to change the ProgramFiles environment variable. In the case where you double-click to launch it, it's a 32-bit process from the beginning.
It seems you're not the only one to encounter this; this Windows API seems designed specifically to work around the problem you're describing. If nothing else it suggests the behavior you're seeing is by design.
But this is academic. To insulate yourself from this sort of thing, I would get the absolute path to your exe, using something like os.path.realpath(__file__), and go from there.