ModuleNotFoundError: No module named 'gnupg'
Explains why `import gnupg` throws ModuleNotFoundError: No module named 'gnupg' and how to fix it with `pip install python-gnupg`. Use when the gnupg import fails on a fresh environment. Not for GPG binary-not-found errors with the package installed.
ModuleNotFoundError: No module named 'gnupg'
TL;DR: the maintained distribution is called python-gnupg, not gnupg. Run pip install python-gnupg and the import works.
ModuleNotFoundError: No module named 'gnupg'The fix
pip uninstall -y gnupg
pip install python-gnupgVerify:
python -c "import gnupg; print('ok')"Expected output: ok.
Note: python-gnupg wraps the gpg binary, so you also need GnuPG installed on the system (apt install gnupg, brew install gnupg). Without the binary you get a different error at runtime, not this import error.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=python-gnupg+No+module+named+gnupg'
When this applies
import gnupgfails on a fresh virtualenv or container.- You ran
pip install gnupgand got the wrong, outdated package. - Automating encryption or signing with GPG from Python.
When it does NOT apply
- Errors about the gpg binary missing at runtime, which is a system-package problem.
No module named 'gnupg'after installing python-gnupg; then check the active environment.
Why this happens
The same distribution-name versus import-name trap as python-jose and pyOpenSSL, with an extra twist: the obvious gnupg name is taken by an older project. pip installs exactly what you name, so the ModuleNotFoundError persists until you use the real distribution name.
Compatibility
python-gnupg 0.5+. Needs a system GnuPG binary (1.4 or 2.x) for actual crypto operations.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.