0

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?

Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63
AGuler
  • 1

1 Answers1

0

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.

Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63
  • Thanks Erik. I checked the version of backports.zoneinfo and it looks like it is the most recent one. I also checked and I don't have a zoneinfo.py . Is there a command I can run to see where PyInstaller is looking when it tries to import exchangelib? – AGuler Jun 29 '22 at 19:29