已安装cryptography仍遇ModuleNotFoundError:找不到cryptography模块
解决
ModuleNotFoundError: No module named 'cryptography'的方案 1. 确认pip与Python版本匹配
- 执行
python3 --version,确认当前运行的Python是3.11.5 - 执行
pip3 --version,查看pip绑定的Python版本,必须和上述版本一致 - 若版本不匹配,用指定版本的pip安装:
python3.11 -m pip install cryptography==41.0.3
2. 排查虚拟环境问题
- 如果你在用虚拟环境,必须先激活环境再安装包:
- Windows:
venv\Scripts\activate - macOS/Linux:
source venv/bin/activate
- Windows:
- 激活后重新执行
pip install cryptography==41.0.3
3. 验证安装有效性
- 执行
python3 -c "import cryptography; print(cryptography.__version__)",若能输出41.0.3则安装成功 - 若仍报错,强制重装:
pip3 install --force-reinstall cryptography==41.0.3
4. 检查IDE解释器配置
- 用VSCode、PyCharm等IDE时,确认编辑器选择的Python解释器是安装了cryptography的3.11.5版本
- VSCode:点击左下角Python版本切换
- PyCharm:通过
File > Settings > Project > Python Interpreter配置
内容的提问来源于stack exchange,提问作者WFid
相关产品推荐
相关产品推荐

