{"id":369,"library":"pynacl","title":"PyNaCl: Python binding to the Networking and Cryptography (NaCl) library","description":"PyNaCl is a Python binding to the Networking and Cryptography (NaCl) library, providing cryptographic operations such as digital signatures, secret-key and public-key encryption, hashing, and password-based key derivation. The current version is 1.6.2, released on January 1, 2026. PyNaCl follows a regular release cadence, with updates approximately every 1-2 years.","status":"active","version":"1.6.2","language":"python","source_language":"en","source_url":"https://github.com/pyca/pynacl","tags":["cryptography","security","encryption","hashing","digital signatures"],"install":[{"cmd":"pip install pynacl","lang":"bash","label":"Install PyNaCl"}],"dependencies":[{"reason":"PyNaCl is a Python binding to the libsodium library, which provides the underlying cryptographic operations.","package":"libsodium"}],"imports":[{"note":"Ensure correct import path to access PublicKeyBox class.","symbol":"PublicKeyBox","correct":"from nacl.public import PublicKeyBox"},{"note":"Ensure correct import path to access SecretBox class.","symbol":"SecretBox","correct":"from nacl.secret import SecretBox"},{"note":"Ensure correct import path to access SigningKey class.","symbol":"SigningKey","correct":"from nacl.signing import SigningKey"},{"note":"Ensure correct import path to access VerifyKey class.","symbol":"VerifyKey","correct":"from nacl.signing import VerifyKey"}],"quickstart":{"code":"from nacl.public import PrivateKey, PublicKey, PublicKeyBox\n\n# Generate a private key\nprivate_key = PrivateKey.generate()\n\n# Derive the corresponding public key\npublic_key = private_key.public_key\n\n# Create a PublicKeyBox for encryption\nbox = PublicKeyBox(public_key)\n\n# Encrypt a message\nmessage = b\"Secret message\"\nencrypted = box.encrypt(message)\n\n# Decrypt the message\ndecrypted = box.decrypt(encrypted)\nprint(decrypted.decode())","lang":"python","description":"This example demonstrates how to generate a private key, derive the corresponding public key, create a PublicKeyBox for encryption, and encrypt and decrypt a message using PyNaCl."},"warnings":[{"fix":"Upgrade your Python installation to version 3.8 or higher.","message":"PyNaCl 1.6.2 requires Python 3.8 or higher.","severity":"breaking","affected_versions":"1.6.2"},{"fix":"Install the 'libsodium' library using your system's package manager or by following the installation instructions provided in the PyNaCl documentation.","message":"Ensure that the 'libsodium' library is installed on your system, as PyNaCl depends on it for cryptographic operations.","severity":"gotcha","affected_versions":"1.6.2"},{"fix":"Replace `PublicKeyBox` with `Box` in your code. The `Box` class provides equivalent functionality for public-key authenticated encryption. Consult the PyNaCl documentation for guidance on migrating from `PublicKeyBox` to `Box`.","message":"The class `PublicKeyBox` has been removed from the `nacl.public` module in PyNaCl versions 1.5.0 and later. This will result in an `ImportError`.","severity":"breaking","affected_versions":"1.6.2"},{"fix":"Update your code to import 'Box' from 'nacl.public' instead of 'PublicKeyBox'.","message":"The 'PublicKeyBox' class was removed from 'nacl.public' in PyNaCl version 1.6.0. If you are using PyNaCl 1.6.0 or later, use 'Box' instead.","severity":"breaking","affected_versions":"1.6.2"}],"env_vars":null,"last_verified":"2026-05-12T13:20:14.308Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"On Linux, install `build-essential` (Debian/Ubuntu) or `Development Tools` (CentOS/Fedora). On Windows, ensure you have an up-to-date `pip` (use `python -m pip install -U pip`) to leverage pre-built wheels, or install Microsoft Visual C++ Build Tools. If wheels are still an issue, manually install `libsodium` development libraries for your OS and set `SODIUM_INSTALL=system` before `pip install pynacl`.","cause":"PyNaCl often requires compilation of its C dependencies (libsodium) during installation if a pre-built wheel is not available for your system. This error indicates that the 'make' build tool, or other necessary C/C++ compilers, are not installed or not found in your system's PATH.","error":"ERROR: The 'make' utility is missing from PATH"},{"fix":"Ensure `pynacl` is installed in the active Python environment using `pip install pynacl`. If already installed, check for Python version mismatches (e.g., if you have multiple Python installations and `pip` points to a different one). If running in a virtual environment, ensure it's activated. Sometimes reinstalling after upgrading `pip` (`python -m pip install -U pip && pip install pynacl`) can resolve this.","cause":"This error occurs when the `pynacl` package, which is imported as `nacl` in Python code, is either not installed, installed in a different Python environment than the one being used, or its C components (`_sodium`) failed to load correctly during installation.","error":"ModuleNotFoundError: No module named 'nacl'"},{"fix":"Explicitly install `pynacl` using `pip install pynacl`. If you are using `discord.py` or a similar library, you might need to install it with its voice capabilities: `pip install discord.py[voice]` which typically ensures `pynacl` is included. Verify that `pynacl` is installed in the correct Python environment.","cause":"This specific error commonly arises when `pynacl` is a required dependency for another library (e.g., `discord.py` for voice functionalities), but `pynacl` itself is not correctly installed or cannot be found by the dependent library at runtime.","error":"RuntimeError: PyNaCl library needed in order to use voice"}],"ecosystem":"pypi","meta_description":null,"install_score":0,"install_tag":"stale","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}