pypcd4
raw JSON → 1.4.3 verified Mon Apr 27 auth: no python
A Python library for reading and writing PCL (Point Cloud Library) .pcd files, supporting ASCII, binary, and binary_compressed encodings. Current version: 1.4.3, requires Python >=3.8.2, released under MIT license on GitHub.
pip install pypcd4 Common errors
error AttributeError: module 'pypcd4' has no attribute 'PointCloud' ↓
cause Using wrong import path or installing older/conflicting package (e.g., pypcd instead of pypcd4).
fix
Install pypcd4 (pip install pypcd4) and import correctly: from pypcd4 import PointCloud
error ModuleNotFoundError: No module named 'lzf' ↓
cause Missing lzf dependency when using binary_compressed PCD format.
fix
Install pypcd4 with its dependencies: pip install pypcd4. For Python<3.8, you may need to manually install python-neo-lzf or python-lzf.
error ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() ↓
cause Attempting to compare numpy arrays from pc_data in a boolean context, e.g., if pc.pc_data['x'] == 0:
fix
Use numpy element-wise comparison: pc.pc_data['x'][pc.pc_data['x'] == 0] or (pc.pc_data['x'] == 0).any()
error UnicodeDecodeError: 'utf-8' codec can't decode byte 0x... ↓
cause Reading a PCD file with binary encoding as binary_compressed, or vice versa. The library auto-detects but can fail if file is malformed.
fix
Check the PCD file header to determine correct encoding. Use PointCloud.from_path(filename) for auto-detection.
Warnings
breaking Binary_compressed encoding changed in v1.3.0: save/load logic was fixed, which may break compatibility with files created by older versions (<=1.2.1). If you compress with v1.3.0+, older versions may not read them correctly. ↓
fix Re-save any existing binary_compressed PCD files after upgrading to 1.3.0+. If reading old files fails, re-save them in ASCII or binary uncompressed.
deprecated The 'lzf' dependency changed in v1.4.0: 'python-lzf' was replaced with 'python-neo-lzf'. Install may break on older environments if 'python-neo-lzf' is not available for your platform (aarch64 fallback exists but can be problematic). ↓
fix Ensure your system supports python-neo-lzf. If installation fails, try pinning pypcd4<=1.3.0 or installing with --no-deps and manually adding python-lzf.
gotcha PointCloud.pc_data is a numpy structured array, and field access uses column names (e.g., 'x', 'y', 'z', 'rgb'). Attempting to access by index on the structured array may produce unexpected results. ↓
fix Access fields by name: pc.pc_data['x'], pc.pc_data['y'], pc.pc_data['z']. For RGB, note that it's packed into a 32-bit integer; use pc.pc_data['rgb'] and unpack with view(np.uint8).
gotcha When creating from lists using 'from_list', all PointCloud objects must share the same field names/types. Mixing different fields will raise a ValueError. ↓
fix Ensure all point clouds to merge have identical schema. Use PointCloud.fields to inspect before merging.
gotcha Saving to a file with extension other than .pcd is allowed but may cause issues with other PCD readers. The library does not validate the extension. ↓
fix Always use .pcd extension for compatibility.
Imports
- PointCloud
from pypcd4 import PointCloud - PointCloud
from pypcd4.point_cloud import PointCloud - PointCloud wrong
from pypcd4 import PointCloud as PCcorrectimport pypcd4; pypcd4.PointCloud
Quickstart
from pypcd4 import PointCloud
import numpy as np
# Create a simple point cloud
pc = PointCloud.from_xyz_points(np.array([[0,0,0],[1,0,0],[0,1,0]], dtype=np.float32))
print(pc)
# Save to file
pc.save('example.pcd')
# Load from file
loaded = PointCloud.from_path('example.pcd')
print(loaded.pc_data) # numpy structured array