Win32Api导致pyinstaller出现问题

2024-09-19 23:37:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将短脚本转换为可执行文件,但它依赖于win32api,每当我编译脚本并运行它时,几秒钟后就会出现错误“无法执行脚本”。我已经测试过在没有win32api的情况下编译脚本,它工作得非常好。Win32api在文件作为python文件正常运行时工作

import time
import win32api
count = 0
ny = win32api.GetLastInputInfo()
while 1 == 1:
    time.sleep(1)
    oy = ny
    ny = win32api.GetLastInputInfo()
    if count == 2:
            f = open("bruh.txt", "w")
            f.write("bruh")
            f.close()
    if ny == oy:
           count += 1
    else:
           count = 0
C:\Users\mattf\Desktop>pyinstaller --onefile -w test.py
172 INFO: PyInstaller: 3.6
172 INFO: Python: 3.8.2
173 INFO: Platform: Windows-10-10.0.18362-SP0
176 INFO: wrote C:\Users\mattf\Desktop\test.spec
178 INFO: UPX is not available.
193 INFO: Extending PYTHONPATH with paths
['C:\\Users\\mattf\\Desktop', 'C:\\Users\\mattf\\Desktop']
193 INFO: checking Analysis
194 INFO: Building Analysis because Analysis-00.toc is non existent
194 INFO: Initializing module dependency graph...
200 INFO: Caching module graph hooks...
217 INFO: Analyzing base_library.zip ...
4681 INFO: Processing pre-find module path hook   distutils
4683 INFO: distutils: retargeting to non-venv dir 'c:\\users\\mattf\\appdata\\local\\programs\\python\\python38-32\\lib'
9210 INFO: Caching module dependency graph...
9595 INFO: running Analysis Analysis-00.toc
9606 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\mattf\appdata\local\programs\python\python38-32\python.exe
9788 INFO: Analyzing C:\Users\mattf\Desktop\test.py
9792 INFO: Processing module hooks...
9792 INFO: Loading module hook "hook-distutils.py"...
9796 INFO: Loading module hook "hook-encodings.py"...
10089 INFO: Loading module hook "hook-lib2to3.py"...
10097 INFO: Loading module hook "hook-pydoc.py"...
10100 INFO: Loading module hook "hook-sysconfig.py"...
10104 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
10107 INFO: Loading module hook "hook-xml.py"...
10189 INFO: Loading module hook "hook-_tkinter.py"...
10587 INFO: checking Tree
10587 INFO: Building Tree because Tree-00.toc is non existent
10589 INFO: Building Tree Tree-00.toc
10740 INFO: checking Tree
10742 INFO: Building Tree because Tree-01.toc is non existent
10743 INFO: Building Tree Tree-01.toc
10821 INFO: Looking for ctypes DLLs
10880 INFO: Analyzing run-time hooks ...
10887 INFO: Including run-time hook 'pyi_rth__tkinter.py'
10891 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
10907 INFO: Looking for dynamic libraries
11228 WARNING: lib not found: pywintypes38.dll dependency of c:\users\mattf\appdata\local\programs\python\python38-32\lib\site-packages\win32\win32evtlog.pyd
11259 WARNING: lib not found: pywintypes38.dll dependency of c:\users\mattf\appdata\local\programs\python\python38-32\lib\site-packages\win32\win32api.pyd
11540 INFO: Looking for eggs
11540 INFO: Using Python library c:\users\mattf\appdata\local\programs\python\python38-32\python38.dll
11540 INFO: Found binding redirects:
[]
11556 INFO: Warnings written to C:\Users\mattf\Desktop\build\test\warn-test.txt
11671 INFO: Graph cross-reference written to C:\Users\mattf\Desktop\build\test\xref-test.html
11760 INFO: checking PYZ
11763 INFO: Building PYZ because PYZ-00.toc is non existent
11764 INFO: Building PYZ (ZlibArchive) C:\Users\mattf\Desktop\build\test\PYZ-00.pyz
13083 INFO: Building PYZ (ZlibArchive) C:\Users\mattf\Desktop\build\test\PYZ-00.pyz completed successfully.
13130 INFO: checking PKG
13131 INFO: Building PKG because PKG-00.toc is non existent
13134 INFO: Building PKG (CArchive) PKG-00.pkg
16242 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
16313 INFO: Bootloader c:\users\mattf\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\runw.exe
16315 INFO: checking EXE
16316 INFO: Building EXE because EXE-00.toc is non existent
16317 INFO: Building EXE from EXE-00.toc
16318 INFO: Appending archive to EXE C:\Users\mattf\Desktop\dist\test.exe
16352 INFO: Building EXE from EXE-00.toc completed successfully.

Tags: pytestinfotreeishookexeusers