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?