ImportError: No module named win32timezone when i make a singleone exe from a python script with pyInstaller

Question:

I have a script which works when is a py file, but when i use pyInstaller to make one single exe file from that script i will get an error : ImportError: No module named win32timezone.
I import in script:

import win32serviceutil
import win32service
import win32event

and some another modules like subprocess, os, time but i think that 3 are the problem.
Anybody know what is wrong? Thanks!

Asked By: VladutZzZ

||

Answers:

I think you need to follow this section of the Pyinstaller manual:

https://pythonhosted.org/PyInstaller/#id67

Listing Hidden Imports

If Analysis thinks it has found all the imports, but the app fails
with an import error, the problem is a hidden import; that is, an
import that is not visible to the analysis phase.

Hidden imports can occur when the code is using import or perhaps
exec or eval. Hidden imports can also occur when an extension module
uses the Python/C API to do an import. When this occurs, Analysis can
detect nothing. There will be no warnings, only an ImportError at
run-time.

To find these hidden imports, build the app with the -v flag (Getting
Python’s Verbose Imports above) and run it.

Once you know what modules are needed, you add the needed modules to
the bundle using the –hidden-import= command option, or by editing
the spec file, or with a hook file (see Understanding PyInstaller
Hooks below).

Answered By: kotlet schabowy

the -v flag no longer works (shows the version now).

First, find out which module is missing. You can do this by executing the exe through PowerShell/cmd. For example, if your file is “project.exe”, open a PowerShell window in its directory and use the command: .project.exe.

Use this to build the exe:
pyinstaller --hiddenimport win32timezone -F a.py

  • win32timezone was the missing module.
  • Use either -F or –onefile to create a standalone, redistributable exe.
  • You can use –hiddenimport multiple times if you have multiple modules missing.

Reference: https://pythonhosted.org/PyInstaller/usage.html

Answered By: SKS

and only you import win32timezone in the module

import win32com.client as win32
import win32timezone

Answered By: Eduardo Alves
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.