如何使用 win32process(/api/gui) 导入编译 python 文件?
How to compile a python file with win32process(/api/gui) imports?
我正在尝试使用 pyinstaller 将 python 脚本编译为 .exe,但无论我做什么,我似乎都无法让它工作,编译它,创建 .exe ,但是当我 运行 它时,它抛出以下异常:
Traceback (most recent call last):
File "MuteSpotify2.py", line 2, in <module>
ModuleNotFoundError: No module named 'win32process'
[6264] Failed to execute script 'MuteSpotify2' due to unhandled exception!
以下是 运行ning pyinstaller --onefile MuteSpotify2.py -i mutespotify.ico
使用 pyinstaller 创建 .exe 时的日志:
62 INFO: PyInstaller: 4.5.1
62 INFO: Python: 3.9.10
75 INFO: Platform: Windows-10-10.0.19044-SP0
79 INFO: wrote C:\Users\user\Desktop\Testfolder_n01689\MuteSpotify2.spec
82 INFO: UPX is not available.
85 INFO: Extending PYTHONPATH with paths
['C:\Users\user\Desktop\Testfolder_n01689',
'C:\Users\user\Desktop\Testfolder_n01689']
349 INFO: checking Analysis
349 INFO: Building Analysis because Analysis-00.toc is non existent
350 INFO: Initializing module dependency graph...
352 INFO: Caching module graph hooks...
363 INFO: Analyzing base_library.zip ...
2493 INFO: Processing pre-find module path hook distutils from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks\pre_find_module_path\hook-distutils.py'.
2494 INFO: distutils: retargeting to non-venv dir 'F:\Program Files (x86)\Python\python39\lib'
4413 INFO: Caching module dependency graph...
4574 INFO: running Analysis Analysis-00.toc
4589 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by F:\Program Files (x86)\Python\python39\python.exe
4652 WARNING: lib not found: api-ms-win-core-path-l1-1-0.dll dependency of F:\Program Files (x86)\Python\python39\python39.dll
4676 INFO: Analyzing C:\Users\user\Desktop\Testfolder_n01689\MuteSpotify2.py
6485 INFO: Processing pre-find module path hook site from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks\pre_find_module_path\hook-site.py'.
6486 INFO: site: retargeting to fake-dir 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\fake-modules'
8876 INFO: Processing module hooks...
8877 INFO: Loading module hook 'hook-pycparser.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
8878 INFO: Loading module hook 'hook-pygame.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\pygame\__pyinstaller'...
pygame 2.1.1 (SDL 2.0.18, Python 3.9.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
8937 INFO: Loading module hook 'hook-difflib.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
8939 INFO: Loading module hook 'hook-distutils.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
8940 INFO: Loading module hook 'hook-distutils.util.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
8942 INFO: Loading module hook 'hook-encodings.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
9021 INFO: Loading module hook 'hook-heapq.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
9023 INFO: Loading module hook 'hook-lib2to3.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
9099 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
9102 INFO: Loading module hook 'hook-pickle.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
9104 INFO: Loading module hook 'hook-pkg_resources.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
9545 INFO: Processing pre-safe import module hook win32com from 'F:\Program Files (x86)\Python\python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\pre_safe_import_module\hook-win32com.py'.
9604 WARNING: Hidden import "pkg_resources.py2_warn" not found!
9605 WARNING: Hidden import "pkg_resources.markers" not found!
9608 INFO: Loading module hook 'hook-setuptools.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10235 INFO: Loading module hook 'hook-sqlite3.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10314 INFO: Loading module hook 'hook-sysconfig.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10316 INFO: Loading module hook 'hook-win32ctypes.core.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10463 INFO: Loading module hook 'hook-xml.dom.domreg.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10464 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10465 INFO: Loading module hook 'hook-xml.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10467 INFO: Loading module hook 'hook-setuptools.msvc.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10486 INFO: Looking for ctypes DLLs
10555 INFO: Analyzing run-time hooks ...
10559 INFO: Including run-time hook 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgutil.py'
10562 INFO: Including run-time hook 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_multiprocessing.py'
10565 INFO: Including run-time hook 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_inspect.py'
10567 INFO: Including run-time hook 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgres.py'
10577 INFO: Looking for dynamic libraries
11237 INFO: Looking for eggs
11237 INFO: Using Python library F:\Program Files (x86)\Python\python39\python39.dll
11239 INFO: Found binding redirects:
[]
11247 INFO: Warnings written to C:\Users\user\Desktop\Testfolder_n01689\build\MuteSpotify2\warn-MuteSpotify2.txt
11309 INFO: Graph cross-reference written to C:\Users\user\Desktop\Testfolder_n01689\build\MuteSpotify2\xref-MuteSpotify2.html
11323 INFO: checking PYZ
11323 INFO: Building PYZ because PYZ-00.toc is non existent
11323 INFO: Building PYZ (ZlibArchive) C:\Users\user\Desktop\Testfolder_n01689\build\MuteSpotify2\PYZ-00.pyz
11999 INFO: Building PYZ (ZlibArchive) C:\Users\user\Desktop\Testfolder_n01689\build\MuteSpotify2\PYZ-00.pyz completed successfully.
12012 INFO: checking PKG
12012 INFO: Building PKG because PKG-00.toc is non existent
12012 INFO: Building PKG (CArchive) PKG-00.pkg
15003 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
15007 INFO: Bootloader F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
15008 INFO: checking EXE
15008 INFO: Building EXE because EXE-00.toc is non existent
15009 INFO: Building EXE from EXE-00.toc
15012 INFO: Copying icons from ['mutespotify.ico']
15013 INFO: Writing RT_GROUP_ICON 0 resource with 90 bytes
15014 INFO: Writing RT_ICON 1 resource with 13125 bytes
15014 INFO: Writing RT_ICON 2 resource with 67624 bytes
15015 INFO: Writing RT_ICON 3 resource with 16936 bytes
15015 INFO: Writing RT_ICON 4 resource with 9640 bytes
15016 INFO: Writing RT_ICON 5 resource with 4264 bytes
15017 INFO: Writing RT_ICON 6 resource with 1128 bytes
15022 INFO: Updating manifest in C:\Users\user\Desktop\Testfolder_n01689\build\MuteSpotify2\run.exe.nf45kdc0
15023 INFO: Updating resource type 24 name 1 language 0
15027 INFO: Appending archive to EXE C:\Users\user\Desktop\Testfolder_n01689\dist\MuteSpotify2.exe
17299 INFO: Building EXE from EXE-00.toc completed successfully.
我试过 --hidden-import=win32process 也试过解决丢失的 .dll 警告,但无济于事。感谢所有帮助,我也试过 --debug imports 但无法获得更多不幸的是那里的信息..提前致谢!
了解方法:使用 --hidden-import "win32api"
并导入所有 pywin32
内容
我正在尝试使用 pyinstaller 将 python 脚本编译为 .exe,但无论我做什么,我似乎都无法让它工作,编译它,创建 .exe ,但是当我 运行 它时,它抛出以下异常:
Traceback (most recent call last):
File "MuteSpotify2.py", line 2, in <module>
ModuleNotFoundError: No module named 'win32process'
[6264] Failed to execute script 'MuteSpotify2' due to unhandled exception!
以下是 运行ning pyinstaller --onefile MuteSpotify2.py -i mutespotify.ico
使用 pyinstaller 创建 .exe 时的日志:
62 INFO: PyInstaller: 4.5.1
62 INFO: Python: 3.9.10
75 INFO: Platform: Windows-10-10.0.19044-SP0
79 INFO: wrote C:\Users\user\Desktop\Testfolder_n01689\MuteSpotify2.spec
82 INFO: UPX is not available.
85 INFO: Extending PYTHONPATH with paths
['C:\Users\user\Desktop\Testfolder_n01689',
'C:\Users\user\Desktop\Testfolder_n01689']
349 INFO: checking Analysis
349 INFO: Building Analysis because Analysis-00.toc is non existent
350 INFO: Initializing module dependency graph...
352 INFO: Caching module graph hooks...
363 INFO: Analyzing base_library.zip ...
2493 INFO: Processing pre-find module path hook distutils from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks\pre_find_module_path\hook-distutils.py'.
2494 INFO: distutils: retargeting to non-venv dir 'F:\Program Files (x86)\Python\python39\lib'
4413 INFO: Caching module dependency graph...
4574 INFO: running Analysis Analysis-00.toc
4589 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by F:\Program Files (x86)\Python\python39\python.exe
4652 WARNING: lib not found: api-ms-win-core-path-l1-1-0.dll dependency of F:\Program Files (x86)\Python\python39\python39.dll
4676 INFO: Analyzing C:\Users\user\Desktop\Testfolder_n01689\MuteSpotify2.py
6485 INFO: Processing pre-find module path hook site from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks\pre_find_module_path\hook-site.py'.
6486 INFO: site: retargeting to fake-dir 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\fake-modules'
8876 INFO: Processing module hooks...
8877 INFO: Loading module hook 'hook-pycparser.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
8878 INFO: Loading module hook 'hook-pygame.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\pygame\__pyinstaller'...
pygame 2.1.1 (SDL 2.0.18, Python 3.9.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
8937 INFO: Loading module hook 'hook-difflib.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
8939 INFO: Loading module hook 'hook-distutils.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
8940 INFO: Loading module hook 'hook-distutils.util.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
8942 INFO: Loading module hook 'hook-encodings.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
9021 INFO: Loading module hook 'hook-heapq.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
9023 INFO: Loading module hook 'hook-lib2to3.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
9099 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
9102 INFO: Loading module hook 'hook-pickle.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
9104 INFO: Loading module hook 'hook-pkg_resources.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
9545 INFO: Processing pre-safe import module hook win32com from 'F:\Program Files (x86)\Python\python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\pre_safe_import_module\hook-win32com.py'.
9604 WARNING: Hidden import "pkg_resources.py2_warn" not found!
9605 WARNING: Hidden import "pkg_resources.markers" not found!
9608 INFO: Loading module hook 'hook-setuptools.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10235 INFO: Loading module hook 'hook-sqlite3.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10314 INFO: Loading module hook 'hook-sysconfig.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10316 INFO: Loading module hook 'hook-win32ctypes.core.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10463 INFO: Loading module hook 'hook-xml.dom.domreg.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10464 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10465 INFO: Loading module hook 'hook-xml.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10467 INFO: Loading module hook 'hook-setuptools.msvc.py' from 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks'...
10486 INFO: Looking for ctypes DLLs
10555 INFO: Analyzing run-time hooks ...
10559 INFO: Including run-time hook 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgutil.py'
10562 INFO: Including run-time hook 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_multiprocessing.py'
10565 INFO: Including run-time hook 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_inspect.py'
10567 INFO: Including run-time hook 'F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgres.py'
10577 INFO: Looking for dynamic libraries
11237 INFO: Looking for eggs
11237 INFO: Using Python library F:\Program Files (x86)\Python\python39\python39.dll
11239 INFO: Found binding redirects:
[]
11247 INFO: Warnings written to C:\Users\user\Desktop\Testfolder_n01689\build\MuteSpotify2\warn-MuteSpotify2.txt
11309 INFO: Graph cross-reference written to C:\Users\user\Desktop\Testfolder_n01689\build\MuteSpotify2\xref-MuteSpotify2.html
11323 INFO: checking PYZ
11323 INFO: Building PYZ because PYZ-00.toc is non existent
11323 INFO: Building PYZ (ZlibArchive) C:\Users\user\Desktop\Testfolder_n01689\build\MuteSpotify2\PYZ-00.pyz
11999 INFO: Building PYZ (ZlibArchive) C:\Users\user\Desktop\Testfolder_n01689\build\MuteSpotify2\PYZ-00.pyz completed successfully.
12012 INFO: checking PKG
12012 INFO: Building PKG because PKG-00.toc is non existent
12012 INFO: Building PKG (CArchive) PKG-00.pkg
15003 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
15007 INFO: Bootloader F:\Program Files (x86)\Python\python39\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
15008 INFO: checking EXE
15008 INFO: Building EXE because EXE-00.toc is non existent
15009 INFO: Building EXE from EXE-00.toc
15012 INFO: Copying icons from ['mutespotify.ico']
15013 INFO: Writing RT_GROUP_ICON 0 resource with 90 bytes
15014 INFO: Writing RT_ICON 1 resource with 13125 bytes
15014 INFO: Writing RT_ICON 2 resource with 67624 bytes
15015 INFO: Writing RT_ICON 3 resource with 16936 bytes
15015 INFO: Writing RT_ICON 4 resource with 9640 bytes
15016 INFO: Writing RT_ICON 5 resource with 4264 bytes
15017 INFO: Writing RT_ICON 6 resource with 1128 bytes
15022 INFO: Updating manifest in C:\Users\user\Desktop\Testfolder_n01689\build\MuteSpotify2\run.exe.nf45kdc0
15023 INFO: Updating resource type 24 name 1 language 0
15027 INFO: Appending archive to EXE C:\Users\user\Desktop\Testfolder_n01689\dist\MuteSpotify2.exe
17299 INFO: Building EXE from EXE-00.toc completed successfully.
我试过 --hidden-import=win32process 也试过解决丢失的 .dll 警告,但无济于事。感谢所有帮助,我也试过 --debug imports 但无法获得更多不幸的是那里的信息..提前致谢!
了解方法:使用 --hidden-import "win32api"
并导入所有 pywin32
内容