简体   繁体   English

无法解析模块“imaplib2”没有属性“IMAP4_SSL”

[英]Cannot resolve module 'imaplib2' has no attribute 'IMAP4_SSL'

There are many questions regarding imaplib2 has no attribute IMAP4_SSL but none of the solutions in the other questions worked for me.有很多关于imaplib2 has no attribute IMAP4_SSL的问题,但其他问题中的解决方案都没有对我有用。

I have a python script that's been running without issue for years on AWS, but after I upgraded to Ubuntu 20.04.2 LTS , it started throwing the error about IMAP4_SSL .我有一个 python 脚本,它在 AWS 上运行多年没有问题,但是在我升级到Ubuntu 20.04.2 LTS后,它开始抛出关于IMAP4_SSL的错误。 After looking into the issue, I believe it may have something to do with the mappings in Python, but it all looks correct to me.在研究了这个问题之后,我相信它可能与 Python 中的映射有关,但对我来说这一切看起来都是正确的。 I also checked that there are no other Python versions installed that could cause a conflict.我还检查了没有安装可能导致冲突的其他 Python 版本。

Here are the paths for Python and the imaplib2 package这是 Python 和imaplib2 package 的路径

$ which python3
/usr/bin/python3

$ python3 --version
Python 3.8.5

$ whereis python3
'/usr/bin/python3.8-config'
'/usr/bin/python3'
'/usr/bin/python3.8'
'/usr/lib/python3'
'/usr/lib/python3.8'
'/usr/lib/python3.9'
'/etc/python3'
'/etc/python3.8'
'/usr/local/lib/python3.8'
'/usr/include/python3.8'
'/usr/share/python3'
'/usr/share/man/man1/python3.1.gz'

$ sys.path
''
'/usr/lib/python38.zip'
'/usr/lib/python3.8'
'/usr/lib/python3.8/lib-dynload'
'/home/ubuntu/.local/lib/python3.8/site-packages'
'/usr/local/lib/python3.8/dist-packages'
'/usr/lib/python3/dist-packages'
> import imaplib2
> imaplib2.__file__
'/home/ubuntu/.local/lib/python3.8/site-packages/imaplib2/__init__.py'

The problem is likely that you are using an outdated version of imaplib2 from PyPI.问题可能是您使用的是来自 PyPI 的过时版本的imaplib2 You can install a newer version on Ubuntu using the following command.您可以使用以下命令在 Ubuntu 上安装更新版本。

sudo apt install python3-imaplib2

(Alternatively, if you are not on Ubuntu, you can always install from source .) (或者,如果您不在 Ubuntu 上,您可以随时从源代码安装。)

Depending on your PYTHONPATH and the location where you installed the old version of imaplib2 , you may also need to uninstall the old version using pip before import imaplib2 will import the right version.根据您的PYTHONPATH和安装旧版本imaplib2的位置,您可能还需要使用pip卸载旧版本,然后import imaplib2才能导入正确的版本。

python3 -m pip uninstall imaplib2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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