【发布时间】:2021-05-19 16:10:51
【问题描述】:
我在使用 Atom 文本编辑器时遇到了问题。我正在尝试访问 imaplib 包中的 IMAP4_SSL 属性:
import imaplib
...
conn = imaplib.IMAP4_SSL("some.mail.server")
这会引发以下错误:
AttributeError: module 'imaplib' has no attribute 'IMAP4_SSL'
我试图找到它的原因。从 conda 提示符尝试上述代码后,错误消失了。所以,我认为它应该与 Atom 的编辑器或“脚本”包有关。我从 Atom 检查了sys.path 和sys.version,没有任何问题。 python.coffee 配置如下:
exports.Python =
'Selection Based':
command: 'python'
args: (context) ->
code = context.getCode()
tmpFile = GrammarUtils.createTempFileWithCode(code)
return ['-u', tmpFile]
编辑:我认为包导入成功,因为我可以访问它的其他属性,例如IMAP
Edit2:我的问题很可能与我在 Windows Powershell 中启动 python 时得到的以下提示有关:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
我已经尝试运行 activate.bat 脚本,但没有成功,请注意 Anaconda 已安装到 Windows 的另一个驱动器中。但以下路径已经包含在环境变量中:
D:/anaconda
【问题讨论】:
-
无法复制。如果您查看source for imaplib,您会发现 IMAP4_SSL 的存在是有条件的。文档说“要使用这个类,你需要一个使用 SSL 支持编译的套接字模块”。那可能是你的问题
-
是的,你确实是对的
print(imaplib.HAVE_SSL)printsFalse -
所以问题是导入
ssl包我想ImportError: DLL load failed while importing _ssl: The specified module could not be found.
标签: python ssl atom-editor imaplib