Solution when an error occurs when hiding the console screen with PyInstaller

environment

Windows 10 Python 3.6.5 PyInstaller 3.6 Visual Studio Code

Symptoms

pyinstaller --onefile -n appname index.py After executing the above, when I executed the exe generated in the dist folder, it worked without problems. It was annoying that the console screen was displayed, so in the spec file Change console = True to console = False pyinstaller specfilename.spec And run the regenerated exe file,

failed to execute script index

Pop-up is displayed and the process stops. As a test, if you write a simple script and generate an exe with console = False, it will not be reproduced, so I was worried because I didn't know what was the cause.

solution

In the program I wanted to make into an exe this time, I initially imported it as shown below and called the function.

index.py


import funcs

funcs.func1()
funcs.func2()

funcs.py


import anotherfunc

def func1():
    anotherfunc.func3()

otherfunc.py



def func3():

By combining the separate functions into one, as shown below, If you stop importing and using other functions from the destination file, You can now run it even when the console is hidden.

index.py


import funcs

funcs.func1()
funcs.func2()

funcs.py


def func1():
    func3()

def func3():

Recommended Posts

Solution when an error occurs when hiding the console screen with PyInstaller
When I get an error with PyInstaller
Rollback processing when an error occurs with fabric
A memorandum when an error occurs with pip install
After installing CentOS8 with VirtualBox, an error occurs when restarting
What to do when an error occurs with import _ssl
[Beanstalk] What to do when an error occurs with import uuid
[Arch linux] Solution when package-query error occurs
What to do if an error occurs when importing numpy with VScode
An error occurs when importing japandas (problem unsolved)
[Python] I want to know the variables in the function when an error occurs!
An error occurs when trying to import scikit-learn after connecting to Oracle with SQLAlchemy
Investigate the cause when an error is thrown when python3.8 is not found when using lambda-uploader with python3.8
I got an error when using Tensorboard with Pytorch
Solution when pip install from other than the official website and SSL Error (SSL authentication error) occurs
Solution when the image cannot be displayed with tkinter [python]
Error when playing with python
# Solution when pip install gives an error when using Anaconda on Windows 10
Error and solution when installing python3 with homebrew on mac (catalina 10.15)
When I get an error with Pylint in Atom on Windows
I get an error when trying to install maec 4.0.1.0 with pip
[Python] Error and solution memo when using venv with pyenv + anaconda
When I run the exe file with pyinstaller, my PC crashes.
The solution when an empty object is returned in go's json.Marshal
[Question] In sk-learn random forest regression, an error occurs when the number of parallels is set to -1.
[Django] What to do if an Integrity Error occurs when registering data from the management site to the database
When coverage fails with _sqlite3 error
[OSX] [pyenv] What to do when an SSL error occurs in pip
Be careful of the type when making an image mask with Numpy
[AWS] How to deal with WordPress "An error occurred when cropping an image."
What to do if an error occurs when loading a python project created with poetry into VS Code