python-3.x ModuleNotFoundError:没有名为“Crypto”的模块,即使安装了pycyptodome

kb5ga3dv  于 2023-11-20  发布在  Python
关注(0)|答案(1)|浏览(309)

当我需要在MacOS 13.4中使用M1芯片在Python 3.10中导入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信息输出:

> 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:

r55awzrz

r55awzrz1#

不要使用from Crypto.Cipher import PKCS 1_v1_5 as Cipher_pksc1_v1_5,尝试更显式的导入:

from Cryptodome.Cipher import PKCS1_v1_5 as Cipher_pksc1_v1_5
from Cryptodome.PublicKey import RSA

字符串

相关问题