Unable to import Python's email module at all

后端 未结 5 1689
故里飘歌
故里飘歌 2020-12-03 00:55

I can\'t seem to import the email module at all. Every time I do it I get an error. I\'ve tried uninstalling Python and reinstalling, but the email module just refuses to wo

相关标签:
5条回答
  • 2020-12-03 01:15

    It looks like you have a file named email.py. Don't use file names that have the same name as Python standard library modules. Generally, your working directory comes earlier on the Python search path for importing modules so files in your working directory will override modules with the same name in the standard library.

    The clue: note the path names in the traceback

      File "email.py", line 1, in <module>
        import smtplib
      File "C:\Python27\lib\smtplib.py", line 46, in <module>
        import email.utils
    

    By the way, this is a very common error. The excellent tutorial in the Python standard documentation set talks about it here.

    0 讨论(0)
  • 2020-12-03 01:15

    I also came across this error. In addition to renaming the email.py to something else, you must also remove the email.pyc (notice the C) file. After that, all is well. Thanks all!

    0 讨论(0)
  • 2020-12-03 01:15

    I also fetched this problem because i had a file named email.py in my project directory. I wasn't able to import urllib.request . When i changed the file name email.py to emailtest.py then the error gone away. In every time we should not use the name what is same as python core file name.

    0 讨论(0)
  • 2020-12-03 01:23
    npm install email
    

    has fix my problem, try it.

    0 讨论(0)
  • 2020-12-03 01:24

    I just came across this error and wanted to share my solution. In my case, I had a file named email.py in directory. This created a name conflict between Python's email.py and my file. When smtplib tried to import email.utils it looked and my file and didn't find anything. After I renamed my copy of email.py into myemail.py everything worked like a charm.

    0 讨论(0)
提交回复
热议问题