PyInstaller&Pymeasure:NotImplementedError

2024-05-21 04:30:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前在依赖Pymeasure库的代码上使用PyInstaller时遇到困难。程序在提示符下运行正常,但从PyInstaller生成的可执行文件启动时运行不正常。
下面是一个简单的示例,说明代码在提示符下工作,但在冻结时不工作:

import visa
from pymeasure.instruments.keithley import Keithley2000, Keithley2400

rm = visa.ResourceManager()
list_available = rm.list_resources()
print(list_available)

keithley = Keithley2400("GPIB1::23")

keithley.apply_current()                # Sets up to source current
keithley.source_current_range = 10e-3   # Sets the source current range to 10 mA
keithley.compliance_voltage = 10        # Sets the compliance voltage to 10 V
keithley.source_current = 0             # Sets the source current to 0 mA
keithley.enable_source()                # Enables the source output

keithley.measure_voltage()              # Sets up to measure voltage

keithley.ramp_to_current(5e-3)          # Ramps the current to 5 mA
print(keithley.voltage)                 # Prints the voltage in Volts

keithley.shutdown()                     # Ramps the current to 0 mA and disables output

以下是运行可执行文件时的输出:enter image description here

请注意,我已安装PyVISA 1.9.1

为什么会出现此错误?如何修复此错误


Tags: theto代码import可执行文件sourcesetsvisa
2条回答

您需要确保在PyInstaller项目中包含PyVisa的包元数据。PyInstaller有一个utility hook for that job;使用以下内容创建hook-pyvista.py钩子文件(如果您还没有):

from PyInstaller.utils.hooks import copy_metadata

datas = copy_metadata("pyvisa")

并使用 additional-hooks-dir命令行开关告诉PyInstaller。有关更多详细信息,请参见documentation on how hooks work

pymeasurementrelies on the ^{} attribute以确定您是否安装了该项目的正确版本。但是pyvisa.__version__{a4},这将为pkg_resources提供检索其版本所需的元数据

您可以通过自己导入PyVisa并测试__version__属性来验证PyVisa是否已正确安装:

import pyvisa
print("PyVisa version", pyvisa.__version__)

是否确实已连接到仪器,代码引用“GPIB1::23”,但打印(列表可用)返回“GPIB1::24”

相关问题 更多 >