将python文件转换为exe后找不到文件错误 [英] File not found error after converting python file to exe

查看:28
本文介绍了将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-packagesoffice365
untimeauthauthentication_context.py", line 18, in acquire_token_for_user
  File "site-packagesoffice365
untimeauthsaml_token_provider.py", line 57, in acquire_token
  File "site-packagesoffice365
untimeauthsaml_token_provider.py", line 82, in acquire_service_token
  File "site-packagesoffice365
untimeauthsaml_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-packagesoffice365 untimeauthSAML.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

这篇关于将python文件转换为exe后找不到文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆