When I get an error with PyInstaller

PyInstaller is very convenient because you can convert a program written in Python into an executable file. Moreover, if you write it like the following, all the libraries will be combined into one file. Quite convenient.

How to convert test.py to test.exe:

$ pyinstaller test.py --onefile

Installing PyInstaller

You can install PyInstaller using pip as follows.

$ pip install pyinstaller

If you get an error-Python version or macOS

Support for macOS and newer Python versions has been delayed. Use the supported version.

If you get an error-implicit import

If there is an implicit import, you will get an error. As shown below, add the implicit module by adding "--hidden-import = package name".

$ pyinstaller -F --hidden-import="sklearn.utils._cython_blas" --hidden-import="sklearn.neighbors.typedefs" --hidden-import="sklearn.neighbors.quad_tree" --hidden-import="sklearn.tree._utils" test.py

You can also include an implicit module as "import xxx" in your program.

\ _ \ _ File \ _ \ _ and \ _ \ _ dir \ _ \ _ cannot be used when converted to EXE

Therefore, get the path of the exe file with sys.argv [0].

test.py


import os, sys
exe = os.path.abspath(sys.argv[0])
exe_dir = os.path.dirname(exe)

reference

-When an error occurs --stackoverflow -(Notes when converting to EXE) https://qiita.com/ymdymd/items/f9f5587f0f3128285e25

Recommended Posts

When I get an error with PyInstaller
I got an error when saving with OpenCV
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
I get an error with all yum commands
I get an error when I put opencv in pyautoGUI
I get an error when trying meinheld + WebSocket + mongodb
I got an error when using Tensorboard with Pytorch
Solution when an error occurs when hiding the console screen with PyInstaller
When I get a chromedriver error in Selenium
I get a UnicodeDecodeError when running with mod_wsgi
Rollback processing when an error occurs with fabric
I get an OS Error: [Errno 8] Exec format error when running a Flask application with a python command
Workaround if you get an error when trying to install PySide with pip
In the Chainer tutorial, I get an error when importing a package. (mock)
I get an Import Error in Python Beautiful Soup
I got an error when I put opencv in python3 with Raspberry Pi [Remedy]
Error when playing with python
What to do if you get an error when installing python with pyenv
psql: I ran into an error with an invalid option --'''.
A memorandum when an error occurs with pip install
If you get a long error when tabbing an interactive shell with Anaconda
When you get an error in python scraping (requests)
What to do if you get an OpenSSL error when installing Python 2 with pyenv
I get an error when installing scipy on t2.micro because I don't have enough memory
When I try to install mysqlclient with Django, I get error: command'gcc' failed with exit status 1.
I want to get an error message in Japanese with django Password Change Form
What to do if you get an Import Error when importing matplotlib with Jupyter
I got an error when pip install pandas on Mac, so I dealt with it
I get an error when I try to raise Python to 3 series using pyenv on Catalina
I got a Value Error when using JUMAN ++ with PyKNP
I get [Error 2055] when trying to connect to MySQL on Heroku
After installing CentOS8 with VirtualBox, an error occurs when restarting
What to do when an error occurs with import _ssl
When coverage fails with _sqlite3 error
I get an ImportError on appengine_config.py
I sent an SMS with Python
Make Scrapy an exe with Pyinstaller
[Solution] When I try to connect to CloudSQL with GAE, I get an ImportError only when using dev_appserver.
What to do if you get an Undefined error when trying to use pip with pyenv
[Beanstalk] What to do when an error occurs with import uuid
I got an error when I ran composer global require laravel / installer
When I run the exe file with pyinstaller, my PC crashes.
I got an error when I ran meteor add accounts-password and got hooked
I tried sending an SMS with Twilio
I tried to get started with Hy
Note when creating an environment with python
I tried sending an email with python.
Get data from an oscilloscope with pyVISA
I want to get angry with my mom when my memory is tight
I got an error when trying to install Xgboost and its solution
I got an SSL related error with pip install, so I solved it
I get a UnicodeDecodeError when trying to connect to oracle with python sqlalchemy
What to do if an error occurs when importing numpy with VScode
What to do if you get an error when trying to load mnist
I get a Python No module named'encodings' error with the aws command
When I try to upgrade pip, I get an infinite loop after failing to upgrade
What to do if you get an error when installing Dlib (Ubuntu)
[AWS] How to deal with WordPress "An error occurred when cropping an image."
I get an error when I put a Python plugin in Visual Studio Code under the pyenv environment
Error when installing a module with Python pip