Ubuntu18+Python3.6.7下ModuleNotFoundError: No module named 'Crypto'求助
ModuleNotFoundError: No module named 'Crypto' on Ubuntu 18 with Python 3.6.7 Hey there, I’ve run into this exact issue a handful of times—let’s get it sorted out for you. The problem boils down to a common mix-up between the package name you need to install and the module name you import in your code. Here’s what to do step by step:
1. Uninstall conflicting/incorrect packages first
You mentioned installing Crypto and Pcrypto, but those aren’t the right packages for the Crypto module you’re trying to import. Let’s remove them to avoid conflicts:
pip3 uninstall Crypto Pcrypto -y
2. Install the correct package
The active, maintained package that provides the Crypto module is pycryptodome (it’s a drop-in replacement for the outdated pycrypto package, which no longer supports newer Python versions like 3.6). Install it with:
pip3 install pycryptodome
If you have multiple Python versions on your system
Ubuntu 18 might come with other Python versions pre-installed. To make sure the package is installed specifically for Python 3.6, use pip3.6 instead:
pip3.6 install pycryptodome
You can verify which Python version your pip3 targets by running:
pip3 --version
3. Verify the fix
Open a Python 3.6 shell and test the import:
import Crypto print(Crypto.__version__)
If this outputs a version number (like 3.19.0 or similar), you’re good to go—your original code should now run without the ModuleNotFoundError.
Bonus check: Virtual environments
If you’re using a virtual environment for your project, make sure you’ve activated it before running the install commands. Packages installed outside the venv won’t be accessible to code running inside it.
内容的提问来源于stack exchange,提问作者Rasool Ahmed

