Install & Compatibility
Where this runs
tested against v1.7.1 · 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
py 3.9
✕ build_error
✓ 27.5s
602MB installed
● package 602MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
get_sparse_operator
✓ from openfermion import get_sparse_operator
✗ from openfermion.ops import get_sparse_operator
Deprecated path; function is now at top-level
qubit_operator_sparse
✓ from openfermion import qubit_operator_sparse
✗ from openfermion.utils import qubit_operator_sparse
Moved to top-level in v1.0+
MolecularData
✓ from openfermion import MolecularData
✗ from openfermion.hamiltonians import MolecularData
Deprecated submodule; use top-level import
Basic workflow: load molecular data, obtain fermionic Hamiltonian, map to qubit operator, and inspect sparse matrix representation.
import openfermion as of
# Create a simple hydrogen molecule (minimal basis)
geometry = [('H', (0.0, 0.0, 0.0)), ('H', (0.0, 0.0, 0.7414))]
molecule = of.MolecularData(geometry, basis='sto-3g', multiplicity=1, charge=0)
molecule.load()
# Get the fermionic Hamiltonian
hamiltonian = molecule.get_molecular_hamiltonian()
print(hamiltonian)
# Map to qubit Hamiltonian (Jordan-Wigner)
qubit_ham = of.jordan_wigner(hamiltonian)
print(qubit_ham)
# Get sparse matrix
sparse_mat = of.get_sparse_operator(qubit_ham)
print(sparse_mat.shape)
Errors
Common errors & fixes
AttributeError: 'MolecularData' object has no attribute 'n_qubits'
MolecularData was not loaded. Accessing attributes before `.load()` fails.
fixAdd `molecule.load()` after constructing the MolecularData object.
ImportError: cannot import name 'InteractionOperator' from 'openfermion'
In versions >=1.0, the import path changed. InteractionOperator is still available but must be imported from `openfermion.ops` only in older versions.
fixUse `from openfermion import InteractionOperator` (v1.0+) or `from openfermion.ops import InteractionOperator` (v0.x). Check your version.
ModuleNotFoundError: No module named 'openfermionpyscf'
openfermionpyscf is a separate plugin package for PySCF integration. Not included by default.
fixInstall with `pip install openfermionpyscf` and import as `import openfermionpyscf`.
Upgrade
Version history
1.7.1latest on PyPI · released Jun 6, 2025
Audit
Dependencies
cirqoptionalUsed for quantum circuit simulation and interfaces
pyscfoptionalProvides molecular data and integrals
numpyrequiredNumerical computing backbone