PyTango
raw JSON → 10.1.4 verified Fri May 01 auth: no python
PyTango provides Python bindings for the cppTango library, part of the Tango Distributed Control System (DCS). Current version is 10.1.4, with main releases following cppTango major versions. It enables Python device servers and clients for Tango controls.
pip install pytango Common errors
error ModuleNotFoundError: No module named 'tango' ↓
cause PyTango is not installed or not in the Python path.
fix
Run 'pip install pytango' (or 'conda install -c conda-forge pytango'). Ensure virtual environment is activated.
error ImportError: libtango.so: cannot open shared object file: No such file or directory ↓
cause cppTango shared library is not installed or not in LD_LIBRARY_PATH.
fix
Install cppTango via conda ('conda install -c conda-forge cpptango') or set LD_LIBRARY_PATH to the directory containing libtango.so.
error AttributeError: module 'tango' has no attribute 'DeviceClass' ↓
cause Code uses 'from tango import DeviceClass', which moved to tango.server in v10.
fix
Change import to 'from tango.server import DeviceClass'.
Warnings
breaking PyTango 10.x requires Python >=3.10, dropping support for older Python versions. ↓
fix Upgrade to Python 3.10+ or use PyTango 9.x (but 9.x is deprecated).
breaking In PyTango 10, the 'tango' module no longer imports 'DeviceClass' at top level; it moved to 'tango.server'. Code using 'from tango import DeviceClass' will break. ↓
fix Change import to 'from tango.server import DeviceClass'.
gotcha Event subscription callbacks are called from a separate thread, causing potential concurrency issues if not handled properly (e.g., updating GUI). ↓
fix Use thread-safe queues or locking mechanisms when updating shared state from event callbacks.
gotcha Many users try to install pytango via pip without installing cppTango first, leading to compilation errors. ↓
fix Install cppTango using conda (conda install -c conda-forge cpptango) or system package before pip install.
deprecated The 'tango.utils' module is deprecated and may be removed in a future version. ↓
fix Replace uses with standard Python utilities or tango built-ins.
Imports
- DeviceProxy
from tango import DeviceProxy - Database
from tango import Database - DeviceClass wrong
from tango import DeviceClasscorrectfrom tango.server import DeviceClass - command wrong
from tango import commandcorrectfrom tango.server import command
Quickstart
import tango
import os
proxy = tango.DeviceProxy("sys/tg_test/1")
# Read a scalar attribute
print("Attribute value:", proxy.read_attribute("double_scalar").value)
# Write an attribute
proxy.write_attribute("double_scalar", 3.14)
# Execute a command
result = proxy.command_inout("DevString", "hello")
print("Command result:", result)