Registry / serialization / pyvisa

pyvisa

JSON →
library1.16.2pypypi✓ verified 24d ago

PyVISA is a Python package that provides bindings to the "Virtual Instrument Software Architecture" (VISA) library. It enables control of various measurement devices and test equipment (e.g., oscilloscopes, multimeters, power supplies) through different interfaces like GPIB, RS232, USB, and Ethernet. It acts as a frontend to either a vendor-provided VISA shared library (like NI-VISA or Keysight IO Library Suite) or a pure Python implementation like PyVISA-py. The library is actively maintained, with the current version being 1.16.2, and receives regular updates.

pip install -U pyvisa
INSTALL
IMPORT
SIG · PYVISA
P
pyvisa
serializationpythonv1.16.2
Install
1.7s avg
Import
245ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.16.2 · 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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.259s · 20.6MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.7s · import 0.231s · 21MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ResourceManager
from pyvisa import ResourceManager
import visa
While 'import visa' might work in older versions or specific setups, 'import pyvisa' is the canonical and recommended way. Similarly, ResourceManager is accessed as `pyvisa.ResourceManager()`.

This quickstart demonstrates how to initialize the ResourceManager, list available instruments, open a connection to an instrument, query its identification string, and then close the connection. It includes basic error handling and notes for serial configuration. Replace 'YOUR_INSTRUMENT_ADDRESS' with an actual resource string for your device. If no physical VISA backend is found, it automatically uses the PyVISA-py backend if installed.

import os import pyvisa # For simulation or when no physical VISA library is installed, use the PyVISA-py backend # Otherwise, PyVISA will try to find a system-installed VISA library (e.g., NI-VISA) # You can also explicitly specify a backend or path: rm = pyvisa.ResourceManager('@py') # For a specific VISA library path: rm = pyvisa.ResourceManager('/path/to/visa.dll') rm = pyvisa.ResourceManager() try: # List available resources (instruments) resources = rm.list_resources() print(f"Available resources: {resources}") if not resources: print("No instruments found. Ensure your instruments are connected and the VISA backend is correctly configured (e.g., NI-VISA or PyVISA-py).") else: # Open the first available instrument, or a specific one if known # Replace 'YOUR_INSTRUMENT_ADDRESS' with an actual address from rm.list_resources() # e.g., 'GPIB0::12::INSTR', 'ASRL1::INSTR', 'USB0::0xXXXX::0xXXXX::SN::INSTR', 'TCPIP0::192.168.1.100::INSTR' # For this example, we'll try to connect to a dummy address if no real one is found # In a real scenario, you would select an actual instrument from 'resources' instrument_address = os.environ.get('PYVISA_INSTRUMENT_ADDRESS', resources[0] if resources else 'ASRL1::INSTR') # Fallback if no resources if instrument_address.startswith('ASRL') and 'ASRL1::INSTR' in resources: # Special handling for serial, often requires baud_rate # This is a placeholder; actual baud_rate must match the instrument inst = rm.open_resource(instrument_address, baud_rate=9600) inst.write_termination = '\n' inst.read_termination = '\n' else: inst = rm.open_resource(instrument_address) # Query the instrument's identification string idn = inst.query('*IDN?') print(f"Instrument ID: {idn.strip()}") # Example: Write a command and read a response # inst.write('MEAS:VOLT:DC?') # Example SCPI command # response = inst.read() # print(f"Measurement: {response.strip()}") inst.close() print("Instrument connection closed.") except pyvisa.VisaIOError as e: print(f"VISA I/O Error: {e}") print("Ensure the VISA backend is installed and configured, and the instrument address is correct.") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingAPI changes in PyVISA 1.6+ from versions < 1.5. The direct use of `pyvisa.instrument()` and `pyvisa.get_instruments_list()` methods are removed. The `ask()` method on an instrument object was renamed to `query()`.
fix
Replace `pyvisa.instrument("ADDRESS")` with `rm = pyvisa.ResourceManager(); inst = rm.open_resource("ADDRESS")`. Replace `pyvisa.get_instruments_list()` with `rm.list_resources()`. Replace `inst.ask("CMD")` with `inst.query("CMD")`.
affects: < 1.6
gotchaPyVISA requires an underlying VISA implementation. It does not provide the VISA library itself. You must install a vendor's VISA library (e.g., NI-VISA, Keysight IO Library Suite) or the pure Python backend, PyVISA-py.
fix
Install a VISA runtime from a vendor (like National Instruments or Keysight) appropriate for your operating system, or install `pyvisa-py` via `pip install pyvisa-py`.
affects: All
gotchaBitness mismatch between Python and the VISA library can cause 'No matching architecture' errors. For example, a 64-bit Python interpreter cannot load a 32-bit VISA library.
fix
Ensure that your Python installation (32-bit or 64-bit) matches the bitness of the installed VISA shared library.
affects: All
gotchaThe `ResourceManager` might fail to find the VISA library automatically, resulting in an `OSError: Could not find VISA library`.
fix
Explicitly specify the path to the VISA library when creating the ResourceManager, e.g., `rm = pyvisa.ResourceManager('/path/to/visa.dll')`, or configure it in a `.pyvisarc` file.
affects: All
gotchaSerial (ASRL) instruments often require specific baud rates and termination characters to be set for correct communication, which are not always the default.
fix
Consult your instrument's manual for the correct baud rate, `write_termination`, and `read_termination` characters, and set them on the instrument resource object (e.g., `inst.baud_rate = 9600`, `inst.write_termination = '\n'`, `inst.read_termination = '\n'`).
affects: All
deprecatedThe `Instrument.delay` attribute was removed in PyVISA 1.6. Also, the `term_chars` attribute for setting termination characters is deprecated.
fix
For delays, use the `query_delay` attribute within `query()` or add delays in your application code. Use `write_termination` and `read_termination` attributes for setting termination characters.
affects: >= 1.6
Upgrade
Version history
1.16.2latest on PyPI · released Feb 27, 2026
Audit
Dependencies
VISA shared library (e.g., NI-VISA, Keysight IO Library Suite)requiredPyVISA acts as a wrapper for an underlying VISA implementation. You must install a vendor-specific VISA library, or use pyvisa-py as a pure Python backend.
PySerialoptionalOptional dependency for PyVISA-py to enable Serial (ASRL) resources.
PyUSBoptionalOptional dependency for PyVISA-py to enable USB (USB INSTR/RAW) resources. Requires underlying USB driver library like libusb.
psutiloptionalOptional dependency for PyVISA-py to discover TCPIP (VXI-11) devices across multiple network interfaces.
zeroconfrequiredOptional dependency for PyVISA-py to enable HiSLIP and VICP device discovery.
Agent activity
15 hits · last 30 days
node
12
Resources
pyvisa — pip install pyvisa · libregistry