Reputation: 63
hi I am very new to programming. I made sciprt with Anaconda virtual environment and
python 3.5.6, pyinstaller 3.5, selenium 3.141, pyqt5 5.13.2, pymysql 0.9.3
it works fine in atom. and also works fine when I do
pyinstaller --onefile myapp.py
but when I do
pyinstaller --noconsole --onefile myapp.py
in command prompt it says completed successfully. but when I click myapp.exe, fatal error massage box show up. like below
fatal error detected
failed to execute script MyScript
I searched alot, but couldn't find why.
I did some work as https://stackoverflow.com/a/47229908/12471379 still don't know how to fix.
01.07.20
now I got nothing, not even devTool thing from cmd when I run myapp.exe
which made by pyinstaller --onefile myapp.py
still don't work with --noconsole
01.08.20
I just make new venv, did
pyinstaller --noconsole --onefile --noupx myapp.py
only warning I got is
23142 INFO: Loading module hook "hook-PyQt5.py"...
23352 WARNING: Hidden import "sip" not found!
but since it's only warning. I ignore this. and don't work getting crazy....
01.09.20 problem solved.
I was so stupid.... I believe this happen because I am very new to programming I will leave this so no beginner would make same mistake as me.
if you are not native English speaker. you might have some unicode changing in your script. like this
import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')
I just copy and paste this from my lecture video. so didn't know nothing about this. and still don't know. I think this translate error to my language.
problem was this part.
import io
sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')
don't know exactly why. I just erase it. and change servier.py as https://stackoverflow.com/a/51118530/12471379
than do pyinstaller --clean --noconsole --onefile --noupx myapp.py
works!!!
I know this is so basic mistake. but I hope this might help some beginner.
Upvotes: 0
Views: 1664
Reputation: 390
It seems that your issue was related to the reconfiguration of the encoding of the system standard output and standard error sys.stdout
and sys.stderr
.
If you still want to change the encoding of stdout
and stderr
, the following code should works (without stopping you to use pyinstaller
with the --noconsole
option):
import codecs
if sys.stdout.encoding != 'UTF-8':
sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')
if sys.stderr.encoding != 'UTF-8':
sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict')
Upvotes: 1