python - PyInstaller & Pymeasure : NotImplementedError
问题描述
我目前在依赖 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 有一个用于该工作的实用程序挂钩;创建一个hook-pyvista.py
钩子文件(如果你还没有的话):
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata("pyvisa")
并使用--additional-hooks-dir
命令行开关告诉 PyInstaller。有关更多详细信息,请参阅有关挂钩如何工作的文档。
pymeasurement依赖于该pyvisa.__version__
属性来确定您是否安装了该项目的正确版本。但pyvisa.__version__
默认为"unknown"
除非它可以找到它的元数据文件,这将提供pkg_resources
所需的元数据来检索它的版本。
__version__
您可以通过自己导入并测试属性来验证 PyVisa 是否已正确安装:
import pyvisa
print("PyVisa version", pyvisa.__version__)
推荐阅读
- linux - 尝试在 openSUSE Leap 15 下的 GitAhead 中添加远程 GitLab 帐户时 SSL 握手失败
- javascript - 为什么非阻塞异步单线程对于 IO 比阻塞多线程对于某些应用程序更快
- c++ - 如何解决“makefile std error undefined reference”错误?
- amazon-cognito - SAML Azure AD SSO 身份验证和 AWS Cognito
- scala - 我想将架构(元数据)作为参数从 Spark 数据帧/数据集(数据帧名称作为参数)传递
- spring - 如何使用 Hibernate 在我的列表中保存多个相同的实体?
- java - 使用不接受 Scala Map 的脚本 ElasticSearch API 进行更新
- java - 在不超过总和 K 的情况下,可以从两个堆栈顶部移除的最大块数
- git - 确保开发分支包含最新版本分支错误修复的可能解决方案?
- google-apps-script - 如何在 Google 表格中查询数组?