2

I'm trying build an executable of a Python script that reads from a digital multimeter connected via RS232-USB. To build, I'm using cxfreeze.

For this, a setup.py file was written to management. When I run the Python script, everything happens normally. But the built executable doesn't run and shows: ValueError: Could not locate a VISA implementation. Install either the IVI binary or pyvisa-py.

I wrote a simpler code to test, including all the used packages of the main program, but the executable file shows the same error.

The code (test_pyvisa_implementation.py) is:

from matplotlib.figure import Figure
import tkinter as tk
from tkinter import *
import numpy as np
import time, warnings
import pyvisa as visa
from tkinter import filedialog

def port_send():
    global ports
    print(ports.get())

window = tk.Tk()

window.title("Testing pyvisa implementation")

baudRate = 19200
flowCtrl = visa.constants.VI_ASRL_FLOW_NONE

rm = visa.ResourceManager()
com = rm.list_resources()

if com == ():
    com = ['No connection']

ports = tk.StringVar(window)

def refresh_port(ports):
    ports.set('')
    w['menu'].delete(0, 'end')

    com = rm.list_resources()
    print(com)

    if com == ():
        com = ['No connection']

    for choices in com:

        w['menu'].add_command(label=com, command=tk._setit(ports, choices))

w = tk.OptionMenu(window, ports, *com)
w.place(x = 50, y = 0)

refresh = tk.Button(window, text='refresh', command = lambda:refresh_port(ports))
refresh.place(x = 50, y = 80)

confirm = tk.Button(window, text="Confirm", command = lambda:port_send())
confirm.place(x = 50, y = 160)

window.mainloop()

The setup.py is:

import os
from cx_Freeze import setup, Executable
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import tkinter as tk
from tkinter import *
import numpy as np
import time, warnings
import pyvisa as visa
from tkinter import filedialog


base = None

executables = [
        Executable("test_pyvisa_implementation.py", base=base)
]

buildOptions = dict(
        packages = ['matplotlib.backends.backend_tkagg','matplotlib.figure',\
        'tkinter','numpy','time','pyvisa'],
        includes = [],
        include_files = [],
        excludes = []
)


setup(
    name = "TESTING_PYVISA_IMPLEMENTATION",
    version = "1.0",
    description = "DEFAULT",
    options = dict(build_exe = buildOptions),
    executables = executables
 )

The error is:

> Traceback (most recent call last):
  File "/home/lcem/.platformio/penv/lib/python3.8/site-packages/cx_Freeze/initscripts/__startup__.py", line 113, in run
    module_init.run(name + "__main__")
  File "/home/lcem/.platformio/penv/lib/python3.8/site-packages/cx_Freeze/initscripts/Console.py", line 15, in run
    exec(code, module_main.__dict__)
  File "test_pyvisa_implementation.py", line 21, in <module>
  File "/home/lcem/.platformio/penv/lib/python3.8/site-packages/pyvisa/highlevel.py", line 3015, in __new__
    visa_library = open_visa_library(visa_library)
  File "/home/lcem/.platformio/penv/lib/python3.8/site-packages/pyvisa/highlevel.py", line 2924, in open_visa_library
    wrapper = _get_default_wrapper()
  File "/home/lcem/.platformio/penv/lib/python3.8/site-packages/pyvisa/highlevel.py", line 2883, in _get_default_wrapper
    raise ValueError(
ValueError: Could not locate a VISA implementation. Install either the IVI binary or pyvisa-py.

Even if I reinstall the pyvisa-py package, I still get the error. Any suggestions what I can do?

My system information: Linux 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021.

Yan Araújo
  • 25
  • 1
  • 4
  • Tanks for you revision, John! The correct is to management. In pyvisa-py info I get: PyVISA Version: 1.11.3 Backends: ivi: Version: 1.11.3 (bundled with PyVISA) Binary library: Not found – Yan Araújo Nov 15 '21 at 01:17
  • I have this same application on a Windows computer. But on Windows I use a Keithley GPIB controller which is not compatible with Linux. I used VISA because I found it easy to use and I can communicate with RS-232 on Linux and GPIB/IEEE488 on Windows. Can you tell me if I can get the same communication with the GPIB interface using PySerial? If so I could change VISA to PySerial without any problem. – Yan Araújo Nov 15 '21 at 02:15

0 Answers0