我目前在依赖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
请注意,我已安装PyVISA 1.9.1
为什么会出现此错误?如何修复此错误
您需要确保在PyInstaller项目中包含PyVisa的包元数据。PyInstaller有一个utility hook for that job;使用以下内容创建
hook-pyvista.py
钩子文件(如果您还没有):并使用
additional-hooks-dir
命令行开关告诉PyInstaller。有关更多详细信息,请参见documentation on how hooks workpymeasurementrelies on the ^{} attribute 以确定您是否安装了该项目的正确版本。但是
pyvisa.__version__
{a4},这将为pkg_resources
提供检索其版本所需的元数据您可以通过自己导入PyVisa并测试
__version__
属性来验证PyVisa是否已正确安装:是否确实已连接到仪器,代码引用“GPIB1::23”,但打印(列表可用)返回“GPIB1::24”
相关问题 更多 >
编程相关推荐