python 中的 smptlib 和电子邮件模块在导入和 pip 时出错
smptlib and email modules giving error on import and pip in python
我在 python 中使用 smtplib 模块,它突然开始给出 NameError
在 python 中导入 smtblib 或电子邮件时出现以下错误:
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
我在 运行 任何 pip 命令时也遇到同样的错误。对于前。 pip install、pip uninstall、pip freeze 所有命令都给出相同的错误
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
我在 运行 任何 python 脚本时也遇到同样的错误。
有什么解决办法。提前致谢。
我刚刚重新安装了 python 并升级到最新的 9.3 版本,这似乎解决了问题。
我在 python 中使用 smtplib 模块,它突然开始给出 NameError 在 python 中导入 smtblib 或电子邮件时出现以下错误:
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
我在 运行 任何 pip 命令时也遇到同样的错误。对于前。 pip install、pip uninstall、pip freeze 所有命令都给出相同的错误
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
我在 运行 任何 python 脚本时也遇到同样的错误。
有什么解决办法。提前致谢。
我刚刚重新安装了 python 并升级到最新的 9.3 版本,这似乎解决了问题。