如何解决导入streamlit_authenticator时的_rust DLL加载失败错误
问题解决:导入streamlit_authenticator时DLL加载失败
问题描述
使用streamlit开发时,执行import streamlit_authenticator as stauth触发以下报错:
>>> import streamlit_authenticator as stauth Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Lambda\AppData\Roaming\Python\Python310\site-packages\streamlit_authenticator\__init__.py", line 1, in <module> import jwt File "C:\Users\Lambda\AppData\Roaming\Python\Python310\site-packages\jwt\__init__.py", line 17, in <module> from .jwa import std_hash_by_alg File "C:\Users\Lambda\AppData\Roaming\Python\Python310\site-packages\jwt\jwa.py", line 26, in <module> from cryptography.hazmat.primitives.asymmetric import padding File "C:\Users\Lambda\AppData\Roaming\Python\Python310\site-packages\cryptography\hazmat\primitives\asymmetric\padding.py", line 10, in <module> from cryptography.hazmat.primitives import hashes File "C:\Users\Lambda\AppData\Roaming\Python\Python310\site-packages\cryptography\hazmat\primitives\hashes.py", line 10, in <module> from cryptography.hazmat.bindings._rust import openssl as rust_openssl ImportError: DLL load failed while importing _rust: The specified module could not be found.
环境配置:Python 3.10.9、streamlit 1.37.0、Windows 10
解决方案
- 重新安装带预编译二进制的cryptography
卸载当前版本后,强制安装预编译版本,避免本地编译依赖问题:pip uninstall cryptography -y pip install cryptography --only-binary :all: - 配置OpenSSL环境
下载适配Windows 10的OpenSSL安装包完成安装,将其bin目录(如C:\Program Files\OpenSSL-win64\bin)添加到系统PATH环境变量,重启终端后重试导入操作。 - 降级cryptography到兼容版本
部分高版本cryptography的Rust绑定在Python 3.10 Windows环境存在兼容问题,尝试降级到稳定版本:pip install cryptography==39.0.1 - 重建Python虚拟环境
若使用虚拟环境,重新创建环境并重装所有依赖,避免环境损坏:python -m venv new_streamlit_env # Windows激活环境 new_streamlit_env\Scripts\activate pip install streamlit streamlit-authenticator
内容的提问来源于stack exchange,提问作者Lambda
相关产品推荐
相关产品推荐

