简体   繁体   中英

ImportError: cannot import name 'Message' from 'exchangelib.folders'

I am using Python 3.7 (x64) on a Windows 7 machine. I'm recieving the error message below, but when I did research on similar issues, none of the solutions appeared to relevant. The script is named master_pdf_email.py , and is inside a folder with no other.py files. This is on a newly reset computer and is the only other Py script installed, so there is no capacity for any email.py scripts to come into conflict with my current Python runtime.

  • I checked to make sure that this is running on a new, cleanly installed Python distribution.
  • I installed exchangelib 2.0.1 from pip on the same Python instance I'm using to run this.

Code up to when the error is thrown:

import pdfkit, mysql.connector, pprint, json, csv, datetime
from exchangelib import Credentials, Account, FileAttachment
from exchangelib.folders import Message, Mailbox

The traceback for the error message:

    Traceback (most recent call last):
      File "master_email_pdf.py", line 3, in <module>
        from exchangelib.folders import Message, Mailbox
    ImportError: cannot import name 'Message' from 'exchangelib.folders'
    (C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\exchangelib\folders\__init__.py)

You need to import directly from exchangelib for Message and Mailbox .

There is an example showing this on their main page .

If you look at the __init__.py for the primary exchangelib directory, you'll find that Message and Mailbox are being added to __all__ which is where imports are loaded to the namespace. [ code ]

If you look at the folders directory below that, you won't find any Message or Mailbox and within the __init__.py you won't find it either. You could get MailboxAssociations or Messages from .folders if that is what you actually need.

I had the same problem. The problem is that you have a script called email.py which overrides the built-in email module which then fails to import.

I created a new folder and moved my project to it, then my problem solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM