"Failed to execute script" when trying to share exe - python

So I can compile my project and run the .exe perfectly fine on my PC but if I try to share it with others or run it on another PC I get "Failed to execute script WS.py" I tried installing selenium, selenium-wire, python, and pyinstaller all in an env to fix this so the project would have everything it needed installed already.
Here is the error in CMD
Before this I was getting a pop up instead like this
The pop up
I am a nooby programmer so please explain like I'm five, thanks.
EDIT: I also have the exe in the spot where it is needed to run, I did not leave it in the dist folder. As stated it works on my PC but not on others when shared, I feel I am missing something simple here.

Related

How do I solve "pythoncom39.dll could not be located error"?

It has started appearing ever since I installed Anaconda on my PC. It doesn't affect anything and when I press "Ok" it goes away. But it is quite annoying and I would like to know the reason. It has only appeared when I try to run a development server in Django or try to install python modules using pip. Is there any way to solve this?
It happens because anacondaa3\Library\bin\ in this folder pythondicom39.dll has crashed you need to replace it with a new file
Yes, that dll file might be corrupted. Just replace, and then try it. You can download the pythoncom39.dll files from the following link
https://freeonlinestudies.com/python-dlls/

python exe starts and stops immediately on windows 10

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.

Executables made with pyinstaller not working

I've been teaching myself Python3/API/PyQt5 and OOP for the last few weeks and I have finally made an app that works, yay!
I've been working on Ubuntu 19 and the app works fine when I run it from the terminal. The problem is trying to compile it (correct term?) to make it an executable for Linux and Windows.
I used pyinstaller app.py --onefile -w --icon="app.ico" to make the files and I get no errors that I can see.
I used Windows 10 to compire the exe.
Here is the problem: On Linux I get a "shared library" file that doesn't execute and on windows the exe is just broken. All I get is an error saying "this program cannot run on your system", or something similar to that.
This is a very simple, 1 script app with a PyQt5 GUI. I'm pretty new to all of this and this has by far been the hardest part. I've been stuck on this for days and I can't get it to work.
I can give you guys the app code if it will help, I just don't think I have enough rep to post links so it might have to be a code block.
I will be grateful for any help you guys can give as I'm out of ideas.
Cheers!
Editing to add: windows 8.1 gives the error message "Error -3 from inflate: invalid block lengths" when the app.exe is run
After a lot more tinkering I finally have a working exe.
I used -D to make a directory rather than the --onefile as that doesn't work. It makes an exe that doesn't work. Windows complains that it can't unpack the app.
The exe that is inside the dist directory works on Windows 8.1 and Windows 10. Didn't test on Win 7.
I also included the png and ico files and used a clean env with python 3.8 instead of my working env with 3.7 installed. I'm not sure if any of these things made a difference but if anyone else is looking for an answer, this might help.
My final command:
pyinstaller -y -D -w -i "FULL PATH TO ICON .ico" --add-data "FULL PATH TO IMAGE .png";"." "FULL PATH TO PY FILE /app.py"
To make it work on Unix systems you will probably have to use dos2unix "appname" in Terminal, since windows adds some weird endings to any files containing text. That's how it works for me

Can't access local programs from Python script

I´m trying to execute locally installed programs from a Python script (OSX), but they are not found, since /usr/local/bin is not in the PATH. Running os.environ gives only /usr/bin:/bin:/usr/sbin:/sbin.
It is probably a common/simple problem, but I´ve exhausted Google, and start feeling a little stupid :-)
How do you try to execute your programs (please provide us a minimal code sample)?
If you are using the subprocess package, you can try to provide the full path of your executable:
subprocess.run(["/usr/local/bin/my_program"], ...)
Else, you can try to append /usr/local/bin to the os.environ list.

PyInstaller .exe file not working

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.

Categories