与Pyinstaller的Python中的Exchangelib库失败

发布于 2025-02-09 16:16:28 字数 2388 浏览 2 评论 0原文

我正在编写一个将连接到Exchange Server并按计划将电子邮件发送给收件人的应用程序。该应用程序取决于成功的导入式群岛。

当我将程序作为.py文件执行时,我可以导入Exchangelib并获取所需的所有组件。我可以从命令行和jupyter笔记本上成功运行它,但是当我使用pyinstaller将其转换为可执行文件时,它会失败。

这是代码的相关行:

print("Attempting: import exchangelib")
try:
    import exchangelib
    print("SUCCESS: import exchangelib")
except Exception as expOutput:
    print("FAILED: import exchangelib")
    print(expOutput)

print("Attempting: from exchangelib import DELEGATE, Account, Credentials, Configuration, Message, Mailbox, FileAttachment, HTMLBody")
try:
    from exchangelib import DELEGATE, Account, Credentials, Configuration, Message, Mailbox, FileAttachment, HTMLBody
    print("SUCCESS: import DELEGATE, Account, Credentials, Configuration, Message, Mailbox, FileAttachment, HTMLBody")
except Exception as expNewOutput:
    print(expNewOutput)

当我从.py文件(test_exchangelib.py)运行时,我会得到我的期望:

"SUCCESS: import exchangelib"
"SUCCESS: import DELEGATE, Account, Credentials, Configuration, Message, Mailbox, FileAttachment, HTMLBody"

当我以EXE运行时,我会得到以下输出:

    Attempting: import exchangelib
    FAILED: import exchangelib
    module 'zoneinfo' has no attribute 'ZoneInfoNotFoundError'
    Attempting: from exchangelib import DELEGATE, Account, Credentials, Configuration, Message, Mailbox, FileAttachment, HTMLBody
    module 'zoneinfo' has no attribute 'ZoneInfoNotFoundError'

以下是我使用的Pyinstaller命令要将test_exchangelib.py转换为可执行文件:

C:\>cd C:\Users\aguler\AppData\Roaming\Python\Python37

C:\Users\aguler\AppData\Roaming\Python\Python37>ProjectEnvironment\Scripts\activate.bat

(ProjectEnvironment) C:\Users\aguler\AppData\Roaming\Python\Python37>Scripts\pyinstaller --onefile C:\PyFiles\Email_Troubleshoot\Test_exchangelib.py --paths=C:\Users\aguler\AppData\Roaming\Python\Python37\site-packages\tzdata --paths=C:\Users\aguler\AppData\Roaming\Python\Python37\site-packages\tzdata\zoneinfo --paths=C:\users\aguler\appdata\roaming\python\python37\projectenvironment\lib\site-packages\exchangelib --paths=C:\Users\aguler\AppData\Roaming\Python\Python37\ProjectEnvironment\Lib\site-packages\backports

从backports,在account.py文件中调用ZoneInfo类,该文件是通过调用fackyangelib实现的。这意味着可执行文件没有正确地引入Backports,因为它抛弃了ZoneInfo。

我想念什么?如何将整个Backports库进入可执行文件?

I am writing an application that will connect to the Exchange Server and send an email to a recipient on a scheduled basis. This application depends upon a successful import exchanglib.

I'm able to import exchangelib and get all the components I need, when I execute the program as a .py file. I can run it successfully from the command line, as well as from Jupyter Notebook, but it fails when I transform it into an executable, using PyInstaller.

Here are the relevant lines of code:

print("Attempting: import exchangelib")
try:
    import exchangelib
    print("SUCCESS: import exchangelib")
except Exception as expOutput:
    print("FAILED: import exchangelib")
    print(expOutput)

print("Attempting: from exchangelib import DELEGATE, Account, Credentials, Configuration, Message, Mailbox, FileAttachment, HTMLBody")
try:
    from exchangelib import DELEGATE, Account, Credentials, Configuration, Message, Mailbox, FileAttachment, HTMLBody
    print("SUCCESS: import DELEGATE, Account, Credentials, Configuration, Message, Mailbox, FileAttachment, HTMLBody")
except Exception as expNewOutput:
    print(expNewOutput)

When I run this from the .py file (Test_exchangelib.py) I get what I expect:

"SUCCESS: import exchangelib"
"SUCCESS: import DELEGATE, Account, Credentials, Configuration, Message, Mailbox, FileAttachment, HTMLBody"

When I run it as an exe, I get the following output:

    Attempting: import exchangelib
    FAILED: import exchangelib
    module 'zoneinfo' has no attribute 'ZoneInfoNotFoundError'
    Attempting: from exchangelib import DELEGATE, Account, Credentials, Configuration, Message, Mailbox, FileAttachment, HTMLBody
    module 'zoneinfo' has no attribute 'ZoneInfoNotFoundError'

Here are my PyInstaller commands that I use to transform Test_exchangelib.py into an executable:

C:\>cd C:\Users\aguler\AppData\Roaming\Python\Python37

C:\Users\aguler\AppData\Roaming\Python\Python37>ProjectEnvironment\Scripts\activate.bat

(ProjectEnvironment) C:\Users\aguler\AppData\Roaming\Python\Python37>Scripts\pyinstaller --onefile C:\PyFiles\Email_Troubleshoot\Test_exchangelib.py --paths=C:\Users\aguler\AppData\Roaming\Python\Python37\site-packages\tzdata --paths=C:\Users\aguler\AppData\Roaming\Python\Python37\site-packages\tzdata\zoneinfo --paths=C:\users\aguler\appdata\roaming\python\python37\projectenvironment\lib\site-packages\exchangelib --paths=C:\Users\aguler\AppData\Roaming\Python\Python37\ProjectEnvironment\Lib\site-packages\backports

The zoneinfo class is called from backports, in the account.py file which is implemented by calling exchangelib. This means that the executable is not bringing in backports correctly, because it is leaving out zoneInfo.

What am I missing? How can I get the whole backports library into the executable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鯉魚旗 2025-02-16 16:16:28

错误消息意味着Python可以找到Zoneinfo模块,但是ZoneInfo.ZoneInfonotFoundError不存在。 So, you either have a really old version of backports.zoneinfo installed (the class was

The error message means that Python can find a zoneinfo module, but zoneinfo.ZoneInfoNotFoundError does not exist. So, you either have a really old version of backports.zoneinfo installed (the class was introduced in v0.1.0) or the zoneinfo module is picked up from something that is not the backports.zoneinfo package - for example if you have a zoneinfo.py file in your path somewhere.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文