[英]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 文件中的datas
和binaries
.spec
成員)。 請參閱此處和此處的文檔。
在您的datas=
語句中,第二個參數是文件應保存在可執行文件中的位置。 所以你必須把它放在saml_token_provider.py
正在尋找它的文件夾中。 我認為你應該使用類似datas=[ ('/pathtofolder/SAML.xml', 'office365/runtime/auth') ],
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.