有一个导入解析“问题”与passlib,但我预计它不会fi nd sha256_crypt而不是找到passlib。首先,我将确保您的passlib模块已正确安装在您的机器上。其次,我会尝试与错误运行程序,看是否可以运行这样的:如果在运行,那么唯一的“问题”是进口的分辨率是静态的
sha256_crypt.encrypt("someString")
,并不能解决功能这些在运行时没有定义。如果你看一下passlib中的hash.py,这是有意义的。
# NOTE: could support 'non-lazy' version which just imports
# all schemes known to list_crypt_handlers()
#=============================================================================
# import proxy object and replace this module
#=============================================================================
from passlib.registry import _proxy
import sys
sys.modules[__name__] = _proxy
#=============================================================================
# eoc
#=============================================================================
正如你所看到的,sha256_crypt没有在这里定义的,所以进口回来为自己的错误,即使模块在运行时将正确加载!
此时有两种选择。如果您使用的PyDev像我,你可以添加一个忽略标志的进口旁:
from passlib.hash import sha256_crypt #@UnresolvedImport
您还可以修改hash.py这样你定义一个占位符sha256_crypt功能,以确保进口回来的有效的,但实际上这是不是最好的方法,但它的工作:
# NOTE: could support 'non-lazy' version which just imports
# all schemes known to list_crypt_handlers()
#=============================================================================
# import proxy object and replace this module
#=============================================================================
def sha256_crypt():
pass
from passlib.registry import _proxy
import sys
sys.modules[__name__] = _proxy
#=============================================================================
# eoc
#=============================================================================
这将确保进口解决过程将看到函数存在,也不会抱怨。