Perlin Noise
raw JSON → 1.14 verified Sat May 09 auth: no python
A Python implementation of Perlin Noise with support for unlimited coordinate space. Current version 1.14, requires Python >=3.9,<3.13. Released under MIT license. Active development with periodic updates.
pip install perlin-noise Common errors
error ModuleNotFoundError: No module named 'perlin_noise' ↓
cause Package name uses hyphen (perlin-noise) but import requires underscore.
fix
Install with 'pip install perlin-noise' and import as 'from perlin_noise import PerlinNoise'.
error TypeError: argument of type 'int' is not iterable ↓
cause Passing a single integer as coordinate instead of a list/tuple.
fix
Use noise([x]) for 1D or noise([x, y]) for 2D.
error AttributeError: module 'perlin_noise' has no attribute 'PerlinNoise2D' ↓
cause Using deprecated class name removed in version 1.12+.
fix
Update code to use 'from perlin_noise import PerlinNoise' and pass coordinates as list.
Warnings
breaking In version 1.0, the seed parameter was named 'seed' but was renamed to 'random_seed' in a later release (<1.10). If using older code, update to 'seed' or check the version. ↓
fix Use 'seed' for current versions; or pin to older versions if needed.
gotcha The noise output values are not normalized to [0,1] by default; they typically range around [-1,1]. Some users expect a different range. ↓
fix Scale output manually if needed: e.g., (value + 1) / 2 for [0,1].
deprecated The 'PerlinNoise2D' and 'PerlinNoise3D' classes (from older versions) are deprecated; use the general 'PerlinNoise' class with appropriate coordinate dimensions. ↓
fix Use 'from perlin_noise import PerlinNoise' and pass [x,y] or [x,y,z].
Imports
- PerlinNoise
from perlin_noise import PerlinNoise - PerlinNoise wrong
from perlin-noise import PerlinNoisecorrectfrom perlin_noise import PerlinNoise
Quickstart
from perlin_noise import PerlinNoise
import numpy as np
# Create a noise object with seed 10
noise = PerlinNoise(octaves=4, seed=10)
# Generate 2D noise (e.g., 10x10 grid)
freq = 16 # Adjust for desired detail
xp, yp = np.mgrid[0:10, 0:10] / freq
pic = np.array([[noise([x, y]) for y in yp[0]] for x in xp[:,0]])
print(pic.shape) # (10,10)