簡體   English   中英

使用 pyinstaller 將 .py 轉換為 .exe 后缺少模塊

[英]missing modules after converting .py to .exe with pyinstaller

我正在使用pyinstaller.py轉換為.exe但是在轉換后,當我運行.exe ,命令行窗口會突然彈出並關閉。 .exe 幾乎完全不起作用,然后我導航到warn.txt文件,它說有一堆丟失的模塊:

missing module named resource
missing module named posix
missing module named _posixsubprocess
missing module named cv2

並分配更多(共 24 個

我已經研究過這個問題,但無法得到一個好的答案 iv 嘗試使用--onefile--onedir轉換,但同樣的事情發生了。

我如何導入或修復這些丟失的模塊,以便.exe能夠正確運行甚至根本運行?

嘗試制作一個規范文件並為您缺少的模塊使用 hidden_​​imports:

# -*- mode: python -*-
import sys
sys.setrecursionlimit(5000)

block_cipher = None
a = Analysis(['src\\main.py'],
         pathex=['your_path_text'],
         binaries=[],
         datas=[],
         hiddenimports=['cv2','your_missing_modules...],
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='main',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='main')

然后運行pyinstaller main.spec

如果您使用的是虛擬環境,請確保運行正確的 pyinstaller。 您需要使用安裝在該特定 venv 中的那個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM