已安装pycryptodome但无法导入Crypto模块的问题求助
已安装pycryptodome但无法导入Crypto模块的问题求助
我在Python项目里尝试使用pycryptodome库,可一直碰到这个错误:
ModuleNotFoundError: No module named 'Crypto'
下面是我已经做过的所有排查操作:
1. 安装pycryptodome
我通过pip完成了库的安装:
PS C:\Users\Nathan> pip install pycryptodome Requirement already satisfied: pycryptodome in c:\users\nathan\appdata\local\programs\python\python311\lib\site-packages (3.21.0)
2. 验证安装状态
我也确认了库的安装详情:
PS C:\Users\Nathan> pip show pycryptodome Name: pycryptodome Version: 3.21.0 Summary: Cryptographic library for Python Home-page: https://www.pycryptodome.org Author: Helder Eijs Author-email: helderijs@gmail.com License: BSD, Public Domain Location: C:\Users\Nathan\AppData\Local\Programs\Python\Python311\Lib\site-packages Requires: Required-by: cart, eth-keyfile
3. 测试导入失败
但在Python交互环境里尝试导入时直接报错:
PS C:\Users\Nathan> python >>> from Crypto.Cipher import AES Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'Crypto'
4. 尝试卸载重装
我试过完全卸载后强制重新安装:
PS C:\Users\Nathan> pip uninstall pycryptodome -y Found existing installation: pycryptodome 3.21.0 Uninstalling pycryptodome-3.21.0: Successfully uninstalled pycryptodome-3.21.0 PS C:\Users\Nathan> pip install --force-reinstall pycryptodome Collecting pycryptodome Using cached pycryptodome-3.21.0-cp36-abi3-win_amd64.whl.metadata (3.4 kB) Using cached pycryptodome-3.21.0-cp36-abi3-win_amd64.whl (1.8 MB) Installing collected packages: pycryptodome Successfully installed pycryptodome-3.21.0
5. 检查冲突包
我也确认了系统中没有安装会导致冲突的pycrypto包:
PS C:\Users\Nathan> pip uninstall pycrypto -y WARNING: Skipping pycrypto as it is not installed.
6. 验证Python路径
我检查了Python的sys.path,确认包含了pycryptodome所在的site-packages目录:
>>> import sys >>> print(sys.path) ['', 'C:\\Users\\Nathan\\AppData\\Local\\Programs\\Python\\Python311\\python311.zip', 'C:\\Users\\Nathan\\AppData\\Local\\Programs\\Python\\Python311\\DLLs', 'C:\\Users\\Nathan\\AppData\\Local\\Programs\\Python\\Python311\\Lib', 'C:\\Users\\Nathan\\AppData\\Local\\Programs\\Python\\Python311', 'C:\\Users\\Nathan\\AppData\\Roaming\\Python\\Python311\\site-packages', 'C:\\Users\\Nathan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages', 'C:\\Users\\Nathan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\win32', 'C:\\Users\\Nathan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\win32\\lib', 'C:\\Users\\Nathan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\Pythonwin']
其中C:\\Users\\Nathan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages确实在路径列表中。
尽管做了这么多尝试,错误还是没有解决。为什么明明pycryptodome已经安装在正确的目录,我还是会碰到ModuleNotFoundError: No module named 'Crypto'?有没有其他我可以尝试的解决步骤?
备注:内容来源于stack exchange,提问作者Asile34
相关产品推荐
相关产品推荐

