Install & Compatibility
Where this runs
tested against v3.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.306s · 90.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.7s · import 0.318s · 87MB
90MB installed
● package 90MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
GA
✓ import pygad
GA is the class name, but you import the module and use pygad.GA.
Minimal example: maximize sum of binary array (genetic algorithm optimization).
import pygad
import numpy as np
# Define fitness function (must accept two arguments: solution and solution_index)
def fitness_func(solution, solution_idx):
return -np.sum(solution)
# Define gene space
num_genes = 6
gene_space = {'low': 0, 'high': 2, 'step': 1} # integers 0 or 1
# Create GA instance
ga_instance = pygad.GA(
num_generations=10,
num_parents_mating=4,
fitness_func=fitness_func,
sol_per_pop=8,
num_genes=num_genes,
gene_space=gene_space,
parent_selection_type="sss",
keep_parents=1,
crossover_type="single_point",
mutation_type="random",
mutation_num_genes=1
)
# Run GA
ga_instance.run()
# Show best solution
solution, solution_fitness, _ = ga_instance.best_solution()
print(f"Best solution: {solution}")
print(f"Fitness: {solution_fitness}")
Errors
Common errors & fixes
TypeError: 'GA' object is not callable
In versions <3.0.0, the GA class was instantiated directly; in 3.0.0+, the module import changed.
fixUse 'import pygad' and then 'ga = pygad.GA(...)'.
Fitness function must have 2 arguments, but it has 1
After PyGAD 3.0.0, fitness function signature changed to (solution, solution_idx).
fixChange your fitness function to accept a second argument: def fitness_func(solution, solution_idx):
Upgrade
Version history
3.7.0latest on PyPI · released Jun 5, 2026
Audit
Dependencies
numpyrequiredCore dependency for numerical operations.
pygadrequiredLibrary itself.