I was working with smtplib module in python and it suddenly started giving NameError I am getting the following error when importing smtblib or email in python:
Traceback (most recent call last):
File "/Users/Desktop/outlook_email.py", line 25, in <module>
import smtplib
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/smtplib.py", line 48, in <module>
import email.message
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/email/message.py", line 945, in <module>
class MIMEPart(Message):
NameError: name 'Message' is not defined
I am also getting the same error while running any pip command. For ex. pip install, pip uninstall, pip freeze all commands give the same error
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/bin/pip", line 5, in <module>
from pip._internal.cli.main import main
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/cli/main.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/cli/cmdoptions.py", line 24, in <module>
from pip._internal.cli.parser import ConfigOptionParser
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/cli/parser.py", line 12, in <module>
from pip._internal.configuration import Configuration, ConfigurationError
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/configuration.py", line 20, in <module>
from pip._internal.exceptions import (
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/exceptions.py", line 13, in <module>
from pip._vendor.requests.models import Request, Response
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/requests/__init__.py", line 43, in <module>
from pip._vendor import urllib3
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/urllib3/__init__.py", line 11, in <module>
from . import exceptions
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/urllib3/exceptions.py", line 3, in <module>
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 982, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 925, in _find_spec
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/urllib3/packages/six.py", line 192, in find_spec
return spec_from_loader(fullname, self)
File "<frozen importlib._bootstrap>", line 431, in spec_from_loader
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/urllib3/packages/six.py", line 222, in is_package
return hasattr(self.__get_module(fullname), "__path__")
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/urllib3/packages/six.py", line 121, in __getattr__
_module = self._resolve()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/urllib3/packages/six.py", line 118, in _resolve
return _import_module(self.mod)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/urllib3/packages/six.py", line 87, in _import_module
__import__(name)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 72, in <module>
import email.message
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/email/message.py", line 945, in <module>
class MIMEPart(Message):
NameError: name 'Message' is not defined
I am also getting the same error while running any python script.
What can be the solution for this. Thanks in advance.
CodePudding user response:
I just reinstalled my python and upgraded to a latest 9.3 version which seemed to solve the issue.