与Pyinstaller的Python中的Exchangelib库失败
我正在编写一个将连接到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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误消息意味着Python可以找到
Zoneinfo
模块,但是ZoneInfo.ZoneInfonotFoundError
不存在。 So, you either have a really old version ofbackports.zoneinfo
installed (the class wasThe error message means that Python can find a
zoneinfo
module, butzoneinfo.ZoneInfoNotFoundError
does not exist. So, you either have a really old version ofbackports.zoneinfo
installed (the class was introduced in v0.1.0) or thezoneinfo
module is picked up from something that is not thebackports.zoneinfo
package - for example if you have azoneinfo.py
file in your path somewhere.