Can't run exe file which is created by pyinstaller

71
July 16, 2018, at 01:30 AM

I use Pycharm to write the .py source code, it works fine when I use "Run" in Pycharm. After I finishing writing the source code, I want to use Pyinstaller to pack the code to the executable file, the packing process works fine and the .exe file is created. But when I double-click the executable file, there is no any reaction. Don't know what's wrong, please help me. Pyinstaller created a warning report in txt file, but I don't think that's the main reason, I attached it at the bottom anyway.

    (venv) D:\Dropbox\Project\Pycharm Projects\biaobai>pyinstaller -F -w -i aixin.ico main.py
1405 INFO: PyInstaller: 3.3.1
1411 INFO: Python: 3.7.0
1413 INFO: Platform: Windows-10-10.0.17134-SP0
1418 INFO: wrote D:\Dropbox\Project\Pycharm Projects\biaobai\main.spec
1431 INFO: UPX is not available.
1448 INFO: Extending PYTHONPATH with paths
['D:\\Dropbox\\Project\\Pycharm Projects\\biaobai',
 'D:\\Dropbox\\Project\\Pycharm Projects\\biaobai']
1449 INFO: checking Analysis
1449 INFO: Building Analysis because out00-Analysis.toc is non existent
1450 INFO: Initializing module dependency graph...
1455 INFO: Initializing module graph hooks...
1458 INFO: Analyzing base_library.zip ...
6290 INFO: running Analysis out00-Analysis.toc
6321 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by D:\Dropbox\Project\Pycharm Projects\biaobai\venv\Scripts\python.exe
8194 INFO: Caching module hooks...
8206 INFO: Analyzing D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
9513 INFO: Loading module hooks...
9513 INFO: Loading module hook "hook-encodings.py"...
9628 INFO: Loading module hook "hook-PIL.Image.py"...
10335 INFO: Processing pre-find module path hook   distutils
10591 INFO: Loading module hook "hook-PIL.py"...
10607 INFO: Excluding import 'PySide'
10609 INFO:   Removing import of PySide from module PIL.ImageQt
10611 INFO: Import to be excluded not found: 'FixTk'
10612 INFO: Excluding import 'tkinter'
10614 INFO:   Removing import of tkinter from module PIL.ImageTk
10615 INFO: Excluding import 'PyQt4'
10618 INFO:   Removing import of PyQt4 from module PIL.ImageQt
10619 INFO: Excluding import 'PyQt5'
10620 INFO:   Removing import of PyQt5 from module PIL.ImageQt
10621 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
10651 INFO: Import to be excluded not found: 'FixTk'
10651 INFO: Excluding import 'tkinter'
10652 INFO: Loading module hook "hook-pydoc.py"...
10657 INFO: Loading module hook "hook-xml.py"...
11028 INFO: Loading module hook "hook-_tkinter.py"...
11438 INFO: checking Tree
11438 INFO: Building Tree because out00-Tree.toc is non existent
11439 INFO: Building Tree out00-Tree.toc
11549 INFO: checking Tree
11550 INFO: Building Tree because out01-Tree.toc is non existent
11550 INFO: Building Tree out01-Tree.toc
11566 INFO: Loading module hook "hook-distutils.py"...
11609 INFO: Looking for ctypes DLLs
11609 INFO: Analyzing run-time hooks ...
11613 INFO: Including run-time hook 'pyi_rth__tkinter.py'
11624 INFO: Looking for dynamic libraries
13929 INFO: Looking for eggs
13929 INFO: Using Python library D:\Dropbox\Project\Pycharm Projects\biaobai\venv\Scripts\python37.dll
13930 INFO: Found binding redirects:
[]
13934 INFO: Warnings written to D:\Dropbox\Project\Pycharm Projects\biaobai\build\main\warnmain.txt
14026 INFO: Graph cross-reference written to D:\Dropbox\Project\Pycharm Projects\biaobai\build\main\xref-main.html
14105 INFO: checking PYZ
14105 INFO: Building PYZ because out00-PYZ.toc is non existent
14105 INFO: Building PYZ (ZlibArchive) D:\Dropbox\Project\Pycharm Projects\biaobai\build\main\out00-PYZ.pyz
15080 INFO: Building PYZ (ZlibArchive) D:\Dropbox\Project\Pycharm Projects\biaobai\build\main\out00-PYZ.pyz completed successfully.
15095 INFO: checking PKG
15095 INFO: Building PKG because out00-PKG.toc is non existent
15096 INFO: Building PKG (CArchive) out00-PKG.pkg
18477 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
18528 INFO: Bootloader D:\Dropbox\Project\Pycharm Projects\biaobai\venv\lib\site-packages\PyInstaller\bootloader\Windows-32bit\runw.exe
18529 INFO: checking EXE
18529 INFO: Building EXE because out00-EXE.toc is non existent
18530 INFO: Building EXE from out00-EXE.toc
18555 INFO: SRCPATH [('aixin.ico', None)]
18555 INFO: Updating icons from ['aixin.ico'] to C:\Users\ADMINI~1\AppData\Local\Temp\tmp14uu9lyu
18556 INFO: Writing RT_GROUP_ICON 0 resource with 20 bytes
18556 INFO: Writing RT_ICON 1 resource with 28840 bytes
18566 INFO: Appending archive to EXE D:\Dropbox\Project\Pycharm Projects\biaobai\dist\main.exe
18591 INFO: Building EXE from out00-EXE.toc completed successfully.

warnmain.txt :

missing module named resource - imported by posix, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named posix - imported by os, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named _posixsubprocess - imported by subprocess, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named org - imported by pickle, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named readline - imported by cmd, code, pdb, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
excluded module named _frozen_importlib - imported by importlib, importlib.abc, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named _frozen_importlib_external - imported by importlib._bootstrap, importlib, importlib.abc, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named _winreg - imported by platform, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named _scproxy - imported by urllib.request
missing module named java - imported by platform, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named 'java.lang' - imported by platform, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py, xml.sax._exceptions
missing module named vms_lib - imported by platform, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named termios - imported by tty, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py, getpass
missing module named grp - imported by shutil, tarfile, pathlib, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named pwd - imported by posixpath, shutil, tarfile, http.server, webbrowser, pathlib, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py, netrc, getpass
missing module named 'org.python' - imported by copy, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py, xml.sax
missing module named cffi - imported by PIL.Image, PIL.PyAccess, PIL.ImageTk
missing module named Tkinter - imported by PIL.ImageTk
missing module named olefile - imported by PIL.FpxImagePlugin, PIL.MicImagePlugin
missing module named UserDict - imported by PIL.PdfParser
missing module named 'PySide.QtCore' - imported by PIL.ImageQt
missing module named 'PyQt4.QtCore' - imported by PIL.ImageQt
missing module named 'PyQt5.QtCore' - imported by PIL.ImageQt
missing module named numpy - imported by PIL.ImageFilter
missing module named pathlib2 - imported by PIL.Image
missing module named __builtin__ - imported by PIL.Image
Answer 1

What has happened is, Pyinstaller haven't been able to find the paths of some modules you have used in your script. To Resolve the issue, the simplest thing you could do is extending the path. You can run this in the pycharm terminal to add these paths into specs file. Or you could edit the specs file itself.

pyi-makespec --paths=/path/to/thisdir \
             --paths=/path/to/otherdir myscript.py

Include all the other places that the script might be searching for imports.These paths will be added to the sys.path during the analysis.

If this didn't work for you, try hidden imports, extending the package path and adding runtime hooks as shown in here.

Answer 2

I tried to pack the executable file by "pyinstaller -F main.py" instead of using "pyinstaller -F -w main.py". This makes me be able to run the window application through CMD, and then I got the following error:

Fatal Python error: Py_Initialize: Unable to get the locale encoding

zipimport.ZipImportError: can't find module 'encodings' Current

thread 0x00003d20 (most recent call first):

By searching the above error message, I think I get the answer: [zipimport.ZipImportError: can't find module 'encodings' The conclusion should be: Pyinstaller 3.3.1 doesn't support Python 3.7.

Just now, I tried to change my Python version from 3.7 to 3.6.3, the packing works fine, and finally, I was able to run my .exe file normally.

READ ALSO
Get frame type from xbee message in python

Get frame type from xbee message in python

I use python library developed for XBee moduleIn communication, when a message received by the module and transfer to uC, by function "read_data" in XBeeDevice class,the message can be fetch, and by functions in XBeeMessage Class, some parts of the packet...

65
In python,how to use decorator compatible with normal function and coroutine function simply?

In python,how to use decorator compatible with normal function and coroutine function simply?

Here is my way,but I feel it is not very simple, any better way?

60
How to alter a variable defined in a parent class in the child class without altering the parent class variable itself?

How to alter a variable defined in a parent class in the child class without altering the parent class variable itself?

I'm trying to create two subclasses based on the same parent class, so that they each have their own versions of the same variables defined in the parent objectHowever I realized that changing these variables in one of these subclasses will cause the versions...

36
How to “redirect” filesystem read/write calls without root and performance degradation?

How to “redirect” filesystem read/write calls without root and performance degradation?

I have non-root access to a server that is shared by many usersI first develop and run some code locally, and then I want to rsync my data to a temporary location on a remote server and run my code on a remote server without changing any file paths

70