'Pyinstaller: ModuleNotFoundError: No module named 'wmi'; getting several modules not found errors

The command that I am running is pyinstaller --log-level DEBUG beforeLogin.py

When I try and run the executable created using command line I get:

Traceback (most recent call last):
  File "beforeLogin.py", line 2, in <module>
ModuleNotFoundError: No module named 'wmi'
[18908] Failed to execute script beforeLogin

I am not sure how to build my own .spec file but here is the one created by pyinstaller:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['beforeLogin.py'],
             pathex=['C:\\Users\\prana\\Desktop\\GUIApp'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='beforeLogin',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='beforeLogin')

My warn-beforeLogin.txt file located in GUIApp\build\beforeLogin:

This file lists modules PyInstaller was not able to find. This does not
necessarily mean this module is required for running you program. Python and
Python 3rd-party packages include a lot of conditional or optional modules. For
example the module 'ntpath' only exists on Windows, whereas the module
'posixpath' only exists on Posix systems.

Types if import:
* top-level: imported at the top-level - look at these first
* conditional: imported within an if-statement
* delayed: imported from within a function
* optional: imported within a try-except-statement

IMPORTANT: Do NOT post this list to the issue-tracker. Use it as a basis for
           yourself tracking down the missing module. Thanks!

missing module named 'multiprocessing.forking' - imported by C:\Users\prana\AppData\Local\Programs\Python\Python38\Lib\site-packages\PyInstaller\loader\rthooks\pyi_rth_multiprocessing.py (optional)
missing module named 'org.python' - imported by copy (optional), xml.sax (delayed, conditional)
missing module named _frozen_importlib_external - imported by importlib._bootstrap (delayed), importlib (optional), importlib.abc (optional), zipimport (top-level)
excluded module named _frozen_importlib - imported by importlib (optional), importlib.abc (optional), zipimport (top-level)
missing module named _posixshmem - imported by multiprocessing.resource_tracker (conditional), multiprocessing.shared_memory (conditional)
missing module named asyncio.DefaultEventLoopPolicy - imported by asyncio (delayed, conditional), asyncio.events (delayed, conditional)
missing module named termios - imported by tty (top-level), getpass (optional)
missing module named vms_lib - imported by platform (delayed, conditional, optional)
missing module named 'java.lang' - imported by platform (delayed, optional), xml.sax._exceptions (conditional)
missing module named java - imported by platform (delayed)
missing module named _winreg - imported by platform (delayed, optional)
missing module named readline - imported by cmd (delayed, conditional, optional), code (delayed, conditional, optional), pdb (delayed, optional)
missing module named org - imported by pickle (optional)
missing module named posix - imported by os (conditional, optional), shutil (conditional)
missing module named resource - imported by posix (top-level), test.support (optional)
missing module named grp - imported by shutil (optional), tarfile (optional), pathlib (delayed)
missing module named pwd - imported by posixpath (delayed, conditional), shutil (optional), tarfile (optional), pathlib (delayed, conditional, optional), http.server (delayed, optional), webbrowser (delayed), netrc (delayed, conditional), getpass (delayed), distutils.util (delayed, conditional, optional)
missing module named _scproxy - imported by urllib.request (conditional)
missing module named multiprocessing.get_context - imported by multiprocessing (top-level), multiprocessing.pool (top-level), multiprocessing.managers (top-level), multiprocessing.sharedctypes (top-level)
missing module named multiprocessing.TimeoutError - imported by multiprocessing (top-level), multiprocessing.pool (top-level)
missing module named multiprocessing.BufferTooShort - imported by multiprocessing (top-level), multiprocessing.connection (top-level)
missing module named multiprocessing.AuthenticationError - imported by multiprocessing (top-level), multiprocessing.connection (top-level)
missing module named win32evtlog - imported by logging.handlers (delayed, optional)
missing module named win32evtlogutil - imported by logging.handlers (delayed, optional)
missing module named _posixsubprocess - imported by subprocess (optional), multiprocessing.util (delayed)
missing module named multiprocessing.set_start_method - imported by multiprocessing (top-level), multiprocessing.spawn (top-level)
missing module named multiprocessing.get_start_method - imported by multiprocessing (top-level), multiprocessing.spawn (top-level)
missing module named requests - imported by captureImage (top-level), loggedIn (top-level), login (top-level)
missing module named 'selenium.common' - imported by webAutomate (top-level)
missing module named selenium - imported by webAutomate (top-level)
missing module named schedule - imported by webcamPic (top-level), loggedIn (top-level)
missing module named win32api - imported by preventSleep (top-level)
missing module named pyautogui - imported by captureImage (top-level), preventSleep (top-level)
missing module named PIL - imported by captureImage (top-level)
missing module named numpy - imported by captureImage (top-level)
missing module named cv2 - imported by webcamPic (top-level), captureImage (top-level)
missing module named wmi - imported by C:\Users\prana\Desktop\GUIApp\beforeLogin.py (top-level)

Could anyone please help me fix this error? Please let me know if there is anything else I can provide to assist with the debugging.



Solution 1:[1]

Even, I am facing similar issues. What I understood so far is that we need to add hooks files for each module missing. Its painful, if this is the soln offered by pyinstaller. Even standard modules of numpy are not available ....

missing module named numpy.power - imported by numpy (top-level), scipy.stats.kde (top-level) missing module named numpy.hypot - imported by numpy (top-level), scipy.stats.morestats (top-level) missing module named numpy.tanh - imported by numpy (top-level), scipy.stats._discrete_distns (top-level), scipy.fftpack.pseudo_diffs (top-level) missing module named numpy.expm1 - imported by numpy (top-level), scipy.stats._discrete_distns (top-level) missing module named numpy.log1p - imported by numpy (top-level), scipy.stats._discrete_distns (top-level) missing module named numpy.NINF - imported by numpy (top-level), scipy.stats._distn_infrastructure (top-level) missing module named numpy.double - imported by numpy (top-level), scipy.optimize.nnls (top-level) missing module named numpy.greater - imported by numpy (top-level), scipy.optimize.minpack (top-level) missing module named numpy.float64 - imported by numpy (top-level), scipy.optimize.lbfgsb (top-level) missing module named numpy.sinh - imported by numpy (top-level), scipy.signal.filter_design (top-level), scipy.stats._discrete_distns (top-level), scipy.fftpack.pseudo_diffs (top-level) missing module named numpy.arccosh - imported by numpy (top-level), scipy.signal.filter_design (top-level) missing module named numpy.cosh - imported by numpy (top-level), scipy.signal.filter_design (top-level), scipy.stats._discrete_distns (top-level), scipy.fftpack.pseudo_diffs (top-level) missing module named numpy.arcsinh - imported by numpy (top-level), scipy.signal.filter_design (top-level) missing module named numpy.arctan - imported by numpy (top-level), scipy.signal.filter_design (top-level) missing module named numpy.tan - imported by numpy (top-level), scipy.signal.bsplines (top-level), scipy.signal.filter_design (top-level) missing module named numpy.logical_and - imported by numpy (top-level), scipy.signal.bsplines (top-level), scipy.stats._distn_infrastructure (top-level) missing module named numpy.log - imported by numpy (top-level), scipy.signal.waveforms (top-level), scipy.stats._distn_infrastructure (top-level), scipy.stats._discrete_distns (top-level), scipy.stats.morestats (top-level) missing module named numpy.sign - imported by numpy (top-level), scipy.linalg.matfuncs (top-level) missing module named numpy.conjugate - imported by numpy (top-level), scipy.linalg.matfuncs (top-level), scipy.signal.filter_design (top-level) missing module named numpy.logical_not - imported by numpy (top-level), scipy.linalg.matfuncs (top-level) missing module named numpy.single - imported by numpy (top-level), scipy.linalg.decomp_schur (top-level), scipy.linalg.matfuncs (top-level) missing module named numpy.arcsin - imported by numpy (top-level), scipy.linalg.decomp_svd (top-level) missing module named numpy.conj - imported by numpy (top-level), scipy.linalg.decomp (top-level) missing module named numpy.arccos - imported by numpy (top-level), scipy.special.orthogonal (top-level), scipy.linalg.decomp_svd (top-level) missing module named numpy.inexact - imported by numpy (top-level), scipy.special._basic (top-level), scipy.linalg.decomp (top-level), scipy.optimize.minpack (top-level) missing module named commands - imported by numpy.distutils.cpuinfo (conditional)

Solution 2:[2]

In your entry script beforeLogin.py, try doing this

import pythoncom
pythoncom.CoInitialize()
import wmi 

I had an issue bundling wmi as well and the above worked for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prasad Gopalabhatla
Solution 2 Hari