PyVISA
PyVISADocs

Linux Setup

Complete guide to install and configure PyVISA on Linux with NI-VISA drivers, USB permissions, udev rules, and serial port setup.

Install PyVISA

Install the python3-pyvisa package using apt.

sudo apt update
sudo apt install -y python3-pyvisa

Note: installing PyVISA using pip only inside a venv will not work. The package needs to be installed system-wide first.

Test your setup

In the terminal:

python3 -c "import pyvisa; print(pyvisa.ResourceManager('@py').list_resources())"

You should see a list containing your device in the format INTERFACE::VID::PID::SN::INSTR.

Method Using the NI-VISA Backend

Install these if you still do not see your device, for most interfaces pyvisa-py is sufficient.

Step 1: Get the NI-VISA driver and backend

  1. Download the NI package: Visit the NI-VISA download page. Unfortunately, registration is needed. Extract the archive, you should see .deb packages.

Step 2: Install NI-VISA for your distribution

  1. Install NI-VISA: Example for Ubuntu: install the downloaded .deb package using dpkg. There are two packages, a "stream" and fixed quarterly version. Use the fixed quarterly version for reproductibility.

    sudo dpkg -i ni-visa_20*.deb
    sudo apt update
    sudo apt install -y ni-visa

Step 3: Configure PyVISA to Use NI-VISA Backend

  1. Set NI-VISA Backend: Ensure that PyVISA uses the NI-VISA backend.
    import pyvisa
    rm = pyvisa.ResourceManager('@ni')
    You can also provide a direct library path, for example: /usr/lib/x86_64-linux-gnu/libvisa.so. The path for pyvisa-py is @pi.

Step 4: Verify Device Connection

  1. Use visaconf Utility: Use the visaconf NI terminal utility to check your device's connection.

  2. In Python:

python3 -c "import pyvisa; print(pyvisa.ResourceManager('@py').list_resources())"

Virtual Environment (venv)

The python3-pyvisa and python3-pyvisa-py packages must be installed system-wide. After a venv can be used. Installing them in a virtual environment only will not work. Commands for installing in a venv:

pip install PyVISA PyVISA-py

Note: installing the python3-pyvisa package also installs python3-pyvisa-py in debian-based distributions by default. PyVisa-py is a Python VISA backend that replaces the NI backend.

Notes

  • Firewall Settings: For Ethernet devices, ensure your firewall settings allow communication with the instrument.
  • Windows Fast Startup Interference: Windows Fast Startup can prevent interfaces to reset properly and interfere with device detection.
  • Some devices expect termination characters at the end of the commands. Please refer to the dedicated section on the Interfaces page.

On this page

Deploy your PyVISA test scripts with TofuPilot

Trusted by Lyft, Cobot, Pacific Defense, and more.

TofuPilot provides dashboards and analytics to track serial device testing at scale.

TofuPilot
Get Started