Install & Compatibility
Where this runs
tested against v1.4.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.13
✕ build_error
✕ build_error
365MB installed
● package 365MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
BDF
✓ from pyNastran.bdf.bdf import BDF
✗ from pynastran.bdf.bdf import BDF
The PyPI package is 'pynastran', but the internal module name uses 'pyNastran' capitalization.
OP2
✓ from pyNastran.op2.op2 import OP2
✗ from pynastran.op2.op2 import OP2
Consistent with the module capitalization for BDF, the module name is 'pyNastran'.
F06
✓ from pyNastran.f06.f06 import F06
F06 is for reading Nastran output listing files.
This quickstart demonstrates how to create a dummy BDF file, read it using the `BDF` class, and access basic model information like nodes and elements. The `xref=True` argument in `read_bdf` is highlighted as essential for properly populating the model with cross-referenced data.
import os
from pyNastran.bdf.bdf import BDF
# Create a dummy BDF file for demonstration
bdf_content = """
SOL 101
CEND
BEGIN BULK
GRID,1,,0.0,0.0,0.0
GRID,2,,1.0,0.0,0.0
CQUAD4,1,1,1,2,3,4
ENDDATA
"""
dummy_bdf_path = "dummy.bdf"
with open(dummy_bdf_path, "w") as f:
f.write(bdf_content)
# Read the BDF file
model = BDF()
try:
# xref=True is crucial for resolving cross-references and building a complete model
model.read_bdf(dummy_bdf_path, xref=True)
print(f"Successfully read {dummy_bdf_path}")
print(f"Number of GRIDs: {len(model.nodes)}")
print(f"Number of CQUAD4 elements: {len(model.elements)}")
# Accessing specific data (example)
if 1 in model.nodes:
print(f"Node 1 coordinates: {model.nodes[1].xyz}")
except Exception as e:
print(f"Error reading BDF file: {e}")
finally:
# Clean up the dummy file
if os.path.exists(dummy_bdf_path):
os.remove(dummy_bdf_path)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pynastran.bdf'
Attempting to import using the PyPI package name (`pynastran`) directly instead of the correct module name (`pyNastran`).
fixChange your import statement from `from pynastran.bdf.bdf import BDF` to `from pyNastran.bdf.bdf import BDF` (note the capitalization).
KeyError: <some_element_id> (when trying to access elements or nodes from model.elements or model.nodes after reading a BDF)
The BDF model was read without resolving cross-references, leaving the `elements` or `nodes` dictionaries unpopulated or incomplete.
fixEnsure you call `model.read_bdf('your_file.bdf', xref=True)` to populate all model entities and their relationships. AttributeError: 'BDF' object has no attribute 'xyz'
You are trying to access coordinate data directly from the `BDF` model object, but coordinates are attributes of individual `Node` objects within `model.nodes`.
fixAccess node coordinates via `model.nodes[node_id].xyz`. For example, `model.nodes[1].xyz` for node ID 1.
ValueError: cannot find BDF object for card='XXXX' (where XXXX is a Nastran card type)
The BDF file contains a syntax error, an unsupported Nastran card type, or is corrupted, preventing pyNastran from parsing a specific line.
fixInspect the BDF file around the indicated card. Check for typos, incorrect formatting, or ensure the card type is supported by pyNastran for your Nastran version. Refer to Nastran documentation for correct card syntax.
Upgrade
Version history
1.4.1latest on PyPI · released Mar 26, 2024
Audit
Dependencies
numpyrequiredEssential for numerical operations and data structures.
scipyrequiredRequired for various scientific computing tasks, often used with numpy.
matplotliboptionalFor basic plotting functionalities of Nastran models and results.