簡體   English   中英

將 python 文件轉換為 exe 后找不到文件錯誤

[英]File not found error after converting python file to exe

我有用於 SharePoint 登錄的 python 腳本(使用 python office365-rest-python-client)並下載文件。 我想將腳本轉換為可執行文件,以便與非技術人員共享。 Python 代碼運行良好,但是當我使用 Pyinstaller 將其轉換為 exe 並嘗試運行時,它給了我 FileNotFoundError。

我對 python 比較陌生,我嘗試了一些在線找到的教程和解決方案,但沒有運氣。 任何建議,將不勝感激。

謝謝!

Traceback (most recent call last):
  File "test.py", line 107, in <module>
  File "test.py", line 35, in SPLogin
  File "site-packages\office365\runtime\auth\authentication_context.py", line 18, in acquire_token_for_user
  File "site-packages\office365\runtime\auth\saml_token_provider.py", line 57, in acquire_token
  File "site-packages\office365\runtime\auth\saml_token_provider.py", line 82, in acquire_service_token
  File "site-packages\office365\runtime\auth\saml_token_provider.py", line 147, in prepare_security_token_request
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\foo\\AppData\\Local\\Temp\\_MEI66362\\office365\\runtime\\auth\\SAML.xml'
[6664] Failed to execute script test

請參閱下面的規范文件。

SAML.xml 位置:C:\Users\Foo\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\office365\runtime\auth\SAML.Z0F678B78E0133

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

block_cipher = None


a = Analysis(['test.py'],
             pathex=['C:\\Users\\Foo\\Downloads\\sptest\\newbuild'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             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='test',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True )

創建SAML.xml的副本(在我的測試用例中,就在我的 python 腳本test0.py ); 您可以從此頁面復制/粘貼。 然后運行:

pyinstaller --onefile --add-data "SAML.xml;office365/runtime/auth" test0.py

_MEI66362文件夾是在您執行Pyinstaller創建的.exe時創建的。 它將包含Pyinstaller確定的應用程序所需的所有內容。 但是,它不能推斷出您的應用程序需要的每個文件。 在某些情況下,您必須告訴Pyinstaller所需的資源。 您可以使用-add-data--add-binary選項(或 .spec 文件中的datasbinaries .spec成員)。 請參閱此處此處的文檔。

在您的datas=語句中,第二個參數是文件應保存在可執行文件中的位置。 所以你必須把它放在saml_token_provider.py正在尋找它的文件夾中。 我認為你應該使用類似datas=[ ('/pathtofolder/SAML.xml', 'office365/runtime/auth') ],

暫無
暫無

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

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