Error: No module named 'email.utils'; 'email' is not a package

Asked

Viewed 729 times

0

Hello, any script I run, returns me the following error.

 /bin/python3 "/home/Hofferman/Scripts Python/Untitled-1.py"                                                                     1 ↵
Traceback (most recent call last):
  File "/home/Hofferman/Scripts Python/Untitled-1.py", line 2, in <module>
    import urllib.request
  File "/usr/lib64/python3.7/urllib/request.py", line 86, in <module>
    import email
  File "/home/Hofferman/Scripts Python/email.py", line 3, in <module>
    import simplemail
  File "/usr/local/lib/python3.7/site-packages/simplemail/__init__.py", line 22, in <module>
    import smtplib
  File "/usr/lib64/python3.7/smtplib.py", line 47, in <module>
    import email.utils
ModuleNotFoundError: No module named 'email.utils'; 'email' is not a package

Could you help me?

1 answer

2


You created a file on Scripts Python/email.py, see what the name is email.py, this write on the execution the package email native (only for current execution).

So instead of the SMTP class try to look for the modules inside /usr/local/lib/python3.7/site-packages/ he will try to search inside Scripts Python/email.py, or is causing a conflict.

To resolve this just give a different name to your file Scripts Python/email.py, can call it Scripts Python/enviar-email.py, or else you could move auxiliary script to a folder like:

./Scripts Python
  ├───Untitled-1.py
  └───bibliotecas
      ├───email.py
      ├───foo.py
      └───bar.py

And so it would matter in your main script Untitled-1.py:

import bibliotecas.email

Or if you just want some function or class from within the bibliotecas/email.py do:

from foo.email import <nome da função ou classe>

Change <nome da função ou classe> by the name of the function or method you want to use that comes from your script

  • Thank you very much, that’s exactly what you answered.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.