提问人:Dolphin 提问时间:11/11/2023 最后编辑:Dolphin 更新时间:11/12/2023 访问量:54
ModuleNotFoundError:即使安装了 pycryptodome,也没有名为“Crypto”的模块
ModuleNotFoundError: No module named 'Crypto' even through installed pycryptodome
问:
当我需要在带有 M3.10 芯片的 macOS 13.4 中像这样在 Python10 中导入 Crypto 时:
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pksc1_v1_5
from Crypto.PublicKey import RSA
def print_hi(name):
print(f'Hi, {name}')
if __name__ == '__main__':
print_hi('PyCharm')
显示:
Unresolved reference 'Crypto'
我已经尝试过这样安装:pycryptodome
pdm add pycryptodome
仍然无法解决这个问题。我应该怎么做才能解决此问题?这是:pyproject.toml
[project]
name = ""
version = ""
description = ""
authors = [
{name = "JiangXiaoqiang", email = "[email protected]"},
]
dependencies = [
"pycryptodome>=3.19.0",
]
requires-python = ">=3.10"
readme = "README.md"
license = {text = "MIT"}
这是输出:pdm list
> pdm list|grep py
Inside an active virtualenv /Users/xiaoqiangjiang/source/dolphin/visa/venv, reusing it.
Set env var PDM_IGNORE_ACTIVE_VENV to ignore it.
│ rdpywheel │ 0.1.16 │ │
│ python-dateutil │ 2.8.2 │ │
│ pyasn1 │ 0.5.0 │ │
│ pycryptodome │ 3.19.0 │ │
│ openpyxl │ 3.1.2 │ │
│ pycparser │ 2.21 │ │
│ numpy │ 1.26.1 │ │
│ pyOpenSSL │ 21.0.0 │ │
│ python-dotenv │ 1.0.0 │ │
│ pycurl │ 7.45.2 │ │
│ brotlipy │ 0.7.0 │ │
│ pyparsing │ 3.0.9 │ │
这是关于我如何面对问题的 UI:
这是输出的 python:
> which python
/Users/xiaoqiangjiang/PycharmProjects/pythonLearn/venv/bin/python
这是 PDM INFO 输出:
> pdm info
PDM version:
2.10.1
Python Interpreter:
/Users/xiaoqiangjiang/PycharmProjects/pythonLearn/.venv/bin/python (3.10)
Project Root:
/Users/xiaoqiangjiang/PycharmProjects/pythonLearn
Local Packages:
答:
1赞
The JaBo Team
11/11/2023
#1
不要使用 from Crypto.Cipher import PKCS1_v1_5作为Cipher_pksc1_v1_5,而是尝试更显式的导入:
from Cryptodome.Cipher import PKCS1_v1_5 as Cipher_pksc1_v1_5
from Cryptodome.PublicKey import RSA
评论
0赞
Dolphin
11/11/2023
我已经尝试了您所说的,但仍然没有解决此问题。
0赞
The JaBo Team
11/11/2023
嗯,确保检查所有常见错误,例如检查路径、尝试不同版本的 python 和 Cryptodome、检查虚拟环境是否处于活动状态、查看软件包是否甚至使用 @Dolphinpdm list
评论
pdm add pycryptodome