将python文件转换为exe后找不到文件错误
问题描述
我有用于SharePoint登录的python脚本(使用python Office365-睡觉-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-packagesoffice365untimeauthauthentication_context.py", line 18, in acquire_token_for_user
File "site-packagesoffice365untimeauthsaml_token_provider.py", line 57, in acquire_token
File "site-packagesoffice365untimeauthsaml_token_provider.py", line 82, in acquire_service_token
File "site-packagesoffice365untimeauthsaml_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:UsersFooAppDataLocalProgramsPythonPython37-32Libsite-packagesoffice365untimeauthSAML.xml
# -*- 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 )
python
创建SAML.xml
的副本(在我的测试用例中,紧挨着我的推荐答案脚本test0.py
);您可以从this page复制/粘贴。然后运行:
pyinstaller --onefile --add-data "SAML.xml;office365/runtime/auth" test0.py
相关文章