pyinstaller .exe runs from command line, not double click in explorer - python

This has been asked several times before, but the answers don't seem to apply.
I create the exe with this command -
pyinstaller --onefile --add-binary C:\ProgramData\Anaconda3\Library\bin\mkl_intel_thread.1.dll;. unitTracker.py
If I run from the command line it works with no error msgs. If I double click in the File Explorer, the cmd window pops ups, sits around a while, then disappears, never visibly showing an error msg.
I created a simple .bat file:
unitTracker.exe
pause
Now the cmd window stays open after the .exe has run, but it shows nothing.
I added some diagnostic print() to my program, which now starts with:
if (__name__ == '__main__'):
print ('starting')
app = QtWidgets.QApplication(sys.argv)
print ('app created')
myapp = UnitTracker()
myapp.show()
sys.exit(app.exec())
I don't even get the "Starting" output, which suggests the problem is occurring before my program is even loaded.
The problem remains if I remove --onefile
Edit:
I realized that the cmd window in which the program successfully runs is an Anaconda window, whereas double clicking the .bat file produces a default cmd shell. That's one difference. I further refined this to checking the Anaconda env. The program runs in the env that pyinstaller was run in. It does not run in the base Anaconda environment. Isn't pyinstaller supposed to create a standalone program/bundle that doesn't rely on the environment? I know that sometimes it doesn't bundle a .dll without additional prompting, but in that case you get an error that the .dll was not found. I'm getting nothing.
Edit 2:
After a lot of hunting around, I was able to narrow it to a single import, which then allowed me to find the missing module in the huge list of missing modules.
missing module named 'lxml.etree' - imported by openpyxl.xml (delayed, optional), openpyxl.xml.functions (conditional), sphinxcontrib.devhelp (optional)
I've attempted to fix this by adding a --paths= flag pointing to the location of the relevant modules but I can't seem to get the right path. Going to keep banging on it.
Edit 3:
Here's an MWE for the issue:
from openpyxl import Workbook
if (__name__ == '__main__'):
print ("Hello World")
The code will run in the Ananconda shell in which pyinstaller was run. Run from cmd shell and you get nothing.
The warn-test.txt file indicates a missing module lxml.tree, as above.
This issue on the pyinstaller github repo shows the same problem. The solution posted there uses
--collect-submodules lxml
I tried that, but I'm still getting a missing module.
Edit 4:
Although the program runs in the Anaconda env it was built in, it turns out the env does not include lxml. I installed it and the problem has finally gone away.

Related

Pyinstaller - failed to execute script: why?

Fatal Error Detected: Failed to execute script main
I used the following tags:
pyinstaller --onefile -w main.py
I had dependencies, so when it finished, I moved the exe file to the main directory. I'm still getting an error. I used pygame for my project. Why?
I found the answer to my problem. It turns out, it had nothing to do with images. It had to do with the font. Normally, in PyCharm (maybe I'm mistaken) freesansbold.ttf is a default font. However, when PyInstaller packages the files, PyInstaller doesn't have the font downloaded by default, so it gives an error. All I had to do was scour the internet for the font, downloaded it, and it worked.
So yeah, pretty funny mistake.
When you are converting a .py file into .exe, PyInstaller shows the console. If there is an error in your code, it will be displayed in the command prompt.
But if you are converting a .pyw file into .exe, the error will be returned in the form of a message box instead.
So, to see your error (it is really quick though, but it is better than nothing), simply convert your file in .py format into an .exe, to see the error in the command prompt.
But when no window has been open, if there is an error at the beginning of the script, PyInstaller will not detect it as launched, so it will not show an error.
for example this program works, even if there is an error in the code:
avkzebhrkjvzebverybvzkejhrv

exe file made by pyinstaller has problem executing

Here is python script:
I used Visual Studio Code to run the file with this command:
And I get desired result:
Now I tried to create .exe file by opening PowerShell in the folder where is my script and
running next line:
Here is stuff I got(not including otherScripts folder):
Now I open CMD, navigate to the desired folder, and run the .exe file with the next lines of code:
Here is what I get as my first warning:
And here is what I get as a Traceback(console instantly closed and I could not use the snipping tool to capture what was an error, so I run it through C# Win Form application and redirected standard error to a label in form):
I tried:
pip install transformers -U.
instead of --onefile, use command --onedir
line 3 (import tqdm) in the script, was recently added to try to fix the error. Because it says that "tqdm was not found and is required by the application.", so I just put it there.
Updating pyinstaller and transformers to the latest versions.
Other stuff I don't remember right now.
None of these things worked. And I'm kinda stuck here.
I would really appreciate any help to fix this problem.
for me adding the "tqdm directories" to datas solved the problem :)
In script.spec:
datas=[
('C:\\<...>\\Lib\\site-packages\\tqdm', 'tqdm\\'),
('C:\\<...>\\Lib\\site-packages\\tqdm-4.50.2.dist-info', 'tqdm-4.50.2.dist-info\\'),
...],
Try building with --exclude-module=torch?(Taken from: https://github.com/pyinstaller/pyinstaller/issues/4695)

Python app not working after using pyinstaller but doesn't give any errors

So I made an app using python and kvlang, and I was trying to get all the files into a one standalone "exe" file. I needed to include the ".kv" file and my main script. I was using pyinstaller and wrote this command:
pyinstaller --onefile -w --icon=download.ico --add-data filefinder.kv;. filefinder.py
And it all went well - no errors or anything but when I launch the app I just get a quick flash of a white window and then it closes. I have determined that the error must be because of some issue with the ".kv" file but I am not able to fix it cause there's no errors, Nothing! I checked and the app works with the "onedir" option but I need to make it smaller in size. I also tried the "auto-py-to-exe" but it gives the same result. I am happy to provide any more info should you need it to help me resolve this issue. Cheers!
Additional info:
System: Windows 10 pro
Python: 3.9.1
kivy: 2.0.0
Pyinstaller: 4.2
Not sure why it doesn't work, but run the exe in command prompt and then when it fails the error message will not disappear.
Add lots of logs to your application, these can be print statements, as those will always end up on stdout.
i.e. on the first entrypoint, print("Running main")
When you call your first function:
print('calling function_name()')
Once that has finished
print('function_name() complete')
And so on and so forth until you find where exactly the program stops functioning.
Start -> cmd -> navigate to your file using cd -> type in the name of the exe to run it.

Python: no module named 'bottle-websocket' when running an executable made with PyInstaller, including Eel module

I was playing around with the eel module for Python - gives an opportunity to run HTML + CSS/JS with the python functionality.
Made a simple program, tried to make an executable out of it via PyInstaller.
No errors whatsoever, but when running this executable it crashes on the first line - import eel, telling - there is no module called 'bottle-websocket'.
I checked pip: eel, bottle-websocket are installed. Can't figure out what's the problem. Attachments:
main.py:
import eel
from os import path
eel.init(path.dirname(__file__) + "/web")
eel.start('main.html', block=False)
while True:
eel.sleep(10)
Error:
Picture with the error while I try to start the exe
EDIT:
PyInstaller Log
I was also having this same issue, but I finally fixed it, it was actually very very easy, first of all make sure you are using auto-py-to-exe to package your app.
After inserting necessary details (script file,, extra files etc), you would see an advanced options tab probably below, click on it to expand it, look for the hidden imports label and insert "bottle-websocket" in the input field representing the hidden imports, that's basically all you need to do
I HOPE THIS HELPS
Took me the whole day figuring out the solution, but finally, here it is:
Copy the plugin.py, server.py files from C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36-32\lib\site-packages\bottle_websocket to C:\Users*YOUR_USERNAME*\AppData\Local\Programs\Python\Python36-32\Lib
Make sure you have this line as follows in your *.spec file generated by PyInstaller (FOR PYTHON 3.6 32bit):
datas=[('C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36-32\lib\site-packages\eel\eel.js', 'eel'), ('PATH_TO_YOUR_WEB_FOLDER', 'YOUR_WEB_FOLDER_NAME')]
3)Run this command in cmd: python C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36-32\lib\site-packages\eel\main.py HERE_SHOULD_BE_THE_PATH_TO_YOUR_WEB_FOLDER
this command will get the 'bottle-websocket' work and will make sure that it complies with the web folder and files.

Python Subprocess not Running on Jenkins

I have a python script that handles running my unit tests for Eclipse:
Imports projects to a workspace
Builds the project
Runs the Executable
Here is a Gist of my Python script
The cibuild_tests.bat referenced in the script does this:
set eclipse_dir=%1
set workspace_dir=%2
set project_dir=%3
set name=%4
set config=%5
%eclipse_dir% -nosplash --launcher.suppressErrors -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data %workspace_dir% -import %project_dir% -cleanBuild "%name%/%config%"
This all runs perfectly fine, the problem is when subprocess.call(ex) is called in run_executable(...). The output from that executable is never displayed in the console. The output is displayed when the batch script is run for building the project from Eclipse. The executable is a Google Test build and i have it set to output an XML file of the results. I can find no record of the file being created anywhere leading me to believe it is never being run.
But my check to see if the executable exists do find the executable so it is present.
Everything runs just as i expect on my local machine.
Question: What prevents the second subprocess call from outputting to the console, or running, in Jenkins but the first one has no issues?
So i remoted in to the computer and found the issue. It seems a window was popping up reporting a missing DLL for my run process. Once i ensured the DLL was available the error went away and everything built.

Categories

Resources