Python代码转exe时如何导入你需要的模块
How to import the modules you need when converting Python code to exe
使用pyinstaller将Python代码转换为exe文件时,它没有找到我安装的一些模块,因此程序在其他PC上没有运行。
所有插件如下:
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
我去cmd,cd到一个文件中的目录,然后写:
pyinstaller "directory with .py file" -d -x "save directory"
目录中创建了build 和dist 文件夹。我翻遍了它们,我仍然没有找到丢失的模块扔在哪里。找到一个 txt 文件,上面写着他无法捕获。
这里是一个 txt 文件的片段:
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)
告诉我在哪里放置缺少的模块?
我知道这是曲解,但也应该如此
pyinstaller Options: 我找不到关于选项 -x
的任何信息,也许这就是问题所在。
-d
选项似乎需要参数。也许尝试删除该选项或输入所需值之一:
-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.
使用pyinstaller将Python代码转换为exe文件时,它没有找到我安装的一些模块,因此程序在其他PC上没有运行。
所有插件如下:
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
我去cmd,cd到一个文件中的目录,然后写:
pyinstaller "directory with .py file" -d -x "save directory"
目录中创建了build 和dist 文件夹。我翻遍了它们,我仍然没有找到丢失的模块扔在哪里。找到一个 txt 文件,上面写着他无法捕获。
这里是一个 txt 文件的片段:
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)
告诉我在哪里放置缺少的模块?
我知道这是曲解,但也应该如此
pyinstaller Options: 我找不到关于选项 -x
的任何信息,也许这就是问题所在。
-d
选项似乎需要参数。也许尝试删除该选项或输入所需值之一:
-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.