我用 2.7.18 版本的 32 位 python 写了一个与 ads 进行通讯的程序,但是在使用 pyinstaller 打包后运行时总是出现:

Traceback (most recent call last):
File "connect.py",line 7,in <module>
File "Lib\site-packages\PyInstaller\loader\pyimod03_importers.py",line 395,in load_module
File "site-packages\pyads\__init__.py",line 8,in <module>
ImportError:No module named structs
[6236]Failed to execute script connect

的问题,下面是我打包使用的 spec 文件:

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

block_cipher = None


a = Analysis(['connect.py'],
             pathex=['E:\\code_for_work\\working\\connect_software'],
             binaries=[],
             datas=[],
             hiddenimports=[
                 'pynput.keyboard._win32',
                 'pynput.mouse._win32',
                 'pyads',
                 'pyads.structs',
                 'pyads.ads',
                 'pyads.connection',
                 'pyads.pyads_ex',
                 'pyads.constants',
                 'pyads.symbol',
                 'pyads.structs',
                 'six.moves',
                 'importlib.util'
             ],
             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,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='connect',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True )

我在 hiddenimports 中放了 pyads.structs ,但没有用
warn 文件:

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 module. 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 resource - imported by posix (top-level), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named posix - imported by os (conditional, optional), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named _dummy_threading - imported by dummy_threading (top-level), E:\code_for_work\working\connect_software\connect.py (top-level)
runtime module named six.moves - imported by pynput._util (top-level), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named pwd - imported by posixpath (delayed, conditional), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named os2 - imported by os (conditional, optional), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named _emx_link - imported by os (conditional), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named ce - imported by os (conditional, optional), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named riscos - imported by os (conditional, optional), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named riscospath - imported by os (conditional), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named riscosenviron - imported by os (conditional, optional), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named fcntl - imported by tempfile (optional), subprocess (conditional), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named 'org.python' - imported by pickle (optional), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named org - imported by copy (optional), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named readline - imported by cmd (delayed, conditional, optional), pdb (delayed, optional), E:\code_for_work\working\connect_software\connect.py (top-level)
missing module named 'importlib.util' - imported by six (conditional), E:\code_for_work\working\connect_software\connect.py (top-level)
invalid module named pyads.structs - imported by pyads (top-level), E:\code_for_work\working\connect_software\connect.py (top-level)
invalid module named pyads.ads - imported by pyads (top-level), E:\code_for_work\working\connect_software\connect.py (top-level)
invalid module named pyads.connection - imported by pyads (top-level), E:\code_for_work\working\connect_software\connect.py (top-level)
invalid module named pyads.pyads_ex - imported by pyads (top-level), E:\code_for_work\working\connect_software\connect.py (top-level)
invalid module named pyads.constants - imported by pyads (top-level), E:\code_for_work\working\connect_software\connect.py (top-level)
invalid module named pyads.symbol - imported by pyads (top-level), E:\code_for_work\working\connect_software\connect.py (top-level)
应该怎么处理
举报· 67 次点击
登录 注册 站外分享
1 条回复  
zfj1441 小成 2024-8-14 15:44:05
给几个处理方向,1 )升级 python3   2 )使用虚拟环境需要什么库再 pip 安装
返回顶部