PyVISA
PyVISADocs

PyVISA-py Backend

How to use PyVISA-py as a pure-Python VISA backend with no vendor drivers. Setup, limitations, and when to use it.

PyVISA-py is a pure-Python VISA backend. It replaces NI-VISA so you can talk to instruments without installing vendor drivers. Useful on Linux servers, Docker containers, and CI environments where installing NI-VISA is impractical.

Install

pip install pyvisa pyvisa-py

For USB instrument support, you also need a libusb binding:

pip install pyusb

Use PyVISA-py as Backend

Pass "@py" when creating the ResourceManager.

import pyvisa

rm = pyvisa.ResourceManager("@py")
print(rm.list_resources())

inst = rm.open_resource("TCPIP0::192.168.1.50::inst0::INSTR")
print(inst.query("*IDN?"))
inst.close()
rm.close()

Log measurements automatically

TofuPilot records test results from your PyVISA scripts regardless of which backend you use. Free to start.

If you omit the "@py" argument, PyVISA defaults to NI-VISA. If NI-VISA isn't installed, it falls back to PyVISA-py automatically (with a warning).

Interface Support

InterfaceStatusDependencyNotes
TCP/IP (VXI-11)WorksNoneMost common for LAN instruments
TCP/IP (HiSLIP)WorksNoneFaster than VXI-11, preferred for modern instruments
TCP/IP (raw socket)WorksNoneTCPIP0::host::port::SOCKET
Serial (RS-232)WorkspyserialASRL/dev/ttyUSB0::INSTR
USB (USBTMC)Workspyusb + libusbRequires system-level libusb
GPIBNot supportedN/AUse NI-VISA or linux-gpib
PXINot supportedN/AUse NI-VISA
VXINot supportedN/AUse NI-VISA

Install libusb for USB Support

USB instruments need libusb installed at the OS level, not just the Python package.

macOS:

brew install libusb

Ubuntu / Debian:

sudo apt install libusb-1.0-0-dev

Windows:

Download from libusb.info or use Zadig to replace the instrument's driver with WinUSB/libusb.

USB permissions on Linux

By default, USB devices need root access. Add a udev rule to allow your user to access the instrument: echo 'SUBSYSTEM=="usb", MODE="0666"' | sudo tee /etc/udev/rules.d/99-usbtmc.rules then sudo udevadm control --reload-rules.

PyVISA-py vs NI-VISA

CriteriaPyVISA-pyNI-VISA
Installpip install pyvisa-pyDownload from ni.com, run installer
PlatformsAny (pure Python)Windows, Linux, macOS (x86 only)
GPIBNot supportedFull support
USBRequires libusb setupWorks out of the box
TCP/IPFull supportFull support
SerialFull supportFull support
PerformanceGood for most use casesSlightly faster for bulk transfers
Docker / CIEasy, no system deps (unless USB)Hard to install in containers
ARM (Raspberry Pi)WorksNot available

Use PyVISA-py when: you only need TCP/IP or serial, you're on ARM or in a container, or you can't install NI-VISA.

Use NI-VISA when: you need GPIB, you want USB without libusb hassle, or you need maximum transfer speed.

Verify Your Backend

Check which backend PyVISA is actually using:

import pyvisa

rm = pyvisa.ResourceManager("@py")
print(f"Backend: {rm.visalib}")
print(f"Resources found: {rm.list_resources()}")
rm.close()

Expected output:

Backend: /path/to/pyvisa_py/highlevel.py
Resources found: ('TCPIP0::192.168.1.50::inst0::INSTR',)

Simulation Backend

PyVISA includes a @sim backend for testing without hardware. Define instrument responses in a YAML file.

spec: "1.0"
devices:
  device 1:
    dialogues:
      - q: "*IDN?"
        r: "Simulated,Instrument,SN001,1.0"
    resources:
      TCPIP0::192.168.1.50::inst0::INSTR:
        device: device 1
import pyvisa

rm = pyvisa.ResourceManager("simulated.yaml@sim")
inst = rm.open_resource("TCPIP0::192.168.1.50::inst0::INSTR")
print(inst.query("*IDN?"))
inst.close()
rm.close()

This is handy for unit tests and CI pipelines where no instruments are connected.

Troubleshooting

ProblemFix
No module named 'pyvisa_py'pip install pyvisa-py (note the hyphen)
USB device not foundInstall libusb and pyusb, check permissions
Could not locate a VISA implementationPass "@py" explicitly to ResourceManager()
Serial port permission deniedAdd user to dialout group: sudo usermod -aG dialout $USER
HiSLIP connection refusedCheck instrument has HiSLIP enabled (not just VXI-11)