首页 > 解决方案 > Spyder 3.6 AttributeError 中的奇怪行为:模块“EBL”没有属性“EBL”

问题描述

Atm 我正在努力解决一个问题,这让我发疯。这是我的问题:

问题:

我正在尝试使用 dll(称为 EBL.dll)与硬件设备连接,以便发送和接收命令和测量值。我的一位同事支持我,在他的工作站上使用相同的设置(操作系统、python 和 spyder 的版本),一切正常。但是在我的情况下,spyder 总是丢弃错误消息

AttributeError:模块“EBL”没有属性“EBL”

但是,当我按下播放按钮或在 spyder 中运行文件时,总是会发生这种情况。我检查了模块 EBL 的实例包含的属性,并将其与我的同事在相同设置、相同包和相同代码下获得的属性进行了比较。这就是我得到的:

dir(EBL)
Out[18]: ['__doc__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

这就是我的同事得到的:

dir(EBL)
Out[3]:
['CheckDeviceNetConfig',
 'ClearDeviceDiagnosticMemory',
 'ConfigureCommandValueGenerator',
 'ConfigureValveTestSignalgenerator',
 'Connect',
 'DeviceInfo',
 'DeviceOscilloscope',
 'Disconnect',
 'Eal',
 'EasyStartUp',
 'Enable',
 'Equals',
 'Finalize',
 'GetHashCode',
 'GetInterfaceInfo',
 'GetType',
 'InitializeForValveMessurement',
 'IsEasyStartUpOn',
 'IsEnableOn',
 'IsParameterizationLevelOn',
 'LoadParameterfile',
 'LogFilePath',
 'MemberwiseClone',
 'Overloads',
 'ParameterBitCheck',
 'ParameterBitReset',
 'ParameterBitSet',
 'ParameterizationLevel',
 'Password',
 'PowerOff',
 'PowerOn',
 'ReadDataTo16BitArray',
 'ReadListElement',
 'ReadListUInt16',
 'ReadListUInt32',
 'ReferenceEquals',
 'ResetPassword',
 'SaveAllParametersToFile',
 'SaveParametersToFile',
 'SearchForDevices',
 'SetDeviceNetworkConfig',
 'SetDeviceOperatingHours',
 'SetDeviceTime',
 'SetDeviceToOpenLoop',
 'SetMasterCommunicationSercos',
 'SetPassword',
 'SetValveController',
 'SwitchDevicesToTCPIP',
 'ToString',
 'ValueGeneratorEnable',
 'WaitForCommandStatus',
 'WaitForParameterBits',
 'WriteData',
 'WriteListDouble',
 'WriteListUInt16',
 'WriteListUInt32',
 '__call__',
 '__class__',
 '__delattr__',
 '__delitem__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getitem__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__iter__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__overloads__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__setitem__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 'get_DeviceInfo',
 'get_DeviceOscilloscope',
 'get_Eal',
 'get_LogFilePath',
 'get_Password',
 'get_ValueGeneratorEnable',
 'log',
 'set_LogFilePath',
 'set_Password',
 'set_ValueGeneratorEnable']

正如您在以下我们都使用的最小示例中看到的那样,我无法加载属性。

我试过的

我已经尝试了很多东西,比如:

  1. 使用最少的包(包括 pythonnet)创建一个新环境
  2. 通过不同的方式安装pythonnet

conda install -n -c conda-forge pythonnet

点安装pythonnet

pip3 安装 pythonnet

顺便提一句。我知道 conda install 应该比 pip 更受欢迎;)

  1. 使用我同事创建的泡菜文件中的泡菜加载模块作为实例
  2. 将他的工作环境复制并加载为 yml

最小的工作示例

import clr
from os import sys
sys.path.insert(0, "C:/daten")
clr.AddReference('EBL')
import EBL as myebl 
import time
# from EBL import EBL

# Creates EAL connnection object
device = myebl.EBL()

顺便说一句:是的,所有文件都在同一个文件夹中,并且还设置了当前工作目录;)。

这个问题与其他帖子中解决的问题有些不同,因为在这里我不尝试从 py 文件或类加载模块,而是从 dll 加载。前一个工作得很好。

所以我需要回答的问题是:

1、为什么python/spyder/anaconda没有加载整个模块?2.如何让它加载整个模块?

已经提前谢谢你,很抱歉这么长的文字;)

标签: pythonmoduleattributesspyderpython.net

解决方案


推荐阅读