Search code examples
pythonpython-3.xpippyinstallerexe

How to import the modules you need when converting Python code to exe


When converting Python code to exe using pyinstaller, it does not find some modules that I have installed, therefore, the program does not run on other PCs.

All plugins are shown below:

import getpass
import os.path
import random
import smtplib
import ssl
import time
import keyboard
import psutil
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

I go to cmd, cd to a directory in a file, and then write:

pyinstaller "directory with .py file" -d -x "save directory"

The build and dist folders are created in the directory. I rummaged in them, I still did not find where to throw the missing modules. Found a txt-file that says that he could not capture.

here is a snippet from a txt file:

missing module named _posixshmem - imported by multiprocessing.resource_tracker (conditional), multiprocessing.shared_memory (conditional)
missing module named 'org.python' - imported by copy (optional), setuptools.sandbox (conditional), xml.sax (delayed, conditional)
missing module named _scproxy - imported by urllib.request (conditional)
missing module named pwd - imported by posixpath (delayed, conditional), shutil (optional), tarfile (optional), pathlib (delayed, conditional, optional), subprocess (optional), http.server (delayed, optional), webbrowser (delayed ), netrc (delayed, conditional), getpass (delayed), distutils.util (delayed, conditional, optional), psutil (optional), distutils.archive_util (optional)
missing module named urllib.pathname2url - imported by urllib (conditional), PyInstaller.lib.modulegraph._compat (conditional)
missing module named 'java.lang' - imported by platform (delayed, optional), xml.sax._exceptions (conditional)
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 _posixsubprocess - imported by subprocess (optional), multiprocessing.util (delayed)
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), PyInstaller.loader.pyimod02_archive (delayed)
missing module named pep517 - imported by importlib.metadata (delayed)
missing module named posix - imported by os (conditional, optional), shutil (conditional)
missing module named resource - imported by posix (top-level), test.support (delayed, conditional, optional), psutil._pslinux (optional)
missing module named grp - imported by shutil (optional), tarfile (optional), pathlib (delayed, optional), subprocess (optional), distutils.archive_util (optional)
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), psutil._compat (delayed, optional)
missing module named vms_lib - imported by platform (delayed, optional)
missing module named java - imported by platform (delayed)
missing module named _winreg - imported by platform (delayed, optional), pkg_resources._vendor.appdirs (delayed, conditional)
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 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.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 psutil._psutil_aix - imported by psutil (top-level), psutil._psaix (top-level)
missing module named psutil._psutil_sunos - imported by psutil (top-level), psutil._pssunos (top-level)
missing module named psutil._psutil_bsd - imported by psutil (top-level), psutil._psbsd (top-level)
missing module named psutil._psutil_osx - imported by psutil (top-level), psutil._psosx (top-level)
missing module named psutil._psutil_linux - imported by psutil (top-level), psutil._pslinux (top-level)
missing module named fcntl - imported by keyboard._nixcommon (delayed), psutil._compat (delayed, optional)
missing module named dummy_threading - imported by psutil._compat (optional), numpy.distutils.misc_util (optional), numpy.distutils.ccompiler (optional)
missing module named _curses - imported by curses (top-level), curses.has_key (top-level)
missing module named AppKit - imported by keyboard._darwinkeyboard (top-level)
missing module named Quartz - imported by keyboard._darwinkeyboard (top-level)
missing module named Queue - imported by keyboard (optional), keyboard._nixcommon (optional), keyboard._generic (optional)

Tell me where to put the missing modules?

I know that this is a perversion, but it should be so.


Solution

  • pyinstaller Options: I can't find any information about the option -x, maybe this is the issue.

    Also: pyinstaller -d option

    It seems that the -d option requires arguments. Maybe try to remove the option or put one of the required values:

    -d <all,imports,bootloader,noarchive>, --debug <all,imports,bootloader,noarchive>

    Provide assistance with debugging a frozen application. This argument may be provided multiple times to select several of the following options.

    all: All three of the following options.

    imports: specify the -v option to the underlying Python interpreter, causing it to print a message each time a module is initialized, showing the place (filename or built-in module) from which it is loaded. See https://docs.python.org/3/using/cmdline.html#id4.

    bootloader: tell the bootloader to issue progress messages while initializing and starting the bundled app. Used to diagnose problems with missing imports.

    noarchive: instead of storing all frozen Python source files as an archive inside the resulting executable, store them as files in the resulting output directory.