在目标计算机上运行.exe时,缺少Py2exe声明模块

时间:2019-12-05 21:26:46

标签: python-2.7 py2exe pyvisa

我正在使用py2exe将GUI项目转换为可执行文件。我可以很好地创建可执行文件(它可以在安装了python的计算机上运行)。但是,当我将其带到目标计算机时(以Windows 10 virtualbox实例为例),我在日志文件中收到以下错误:

Traceback (most recent call last):
  File "<company-name>_gui.pyw", line 27, in <module>
  File "tab_wrapper.pyc", line 43, in <module>
  File "hwcontrol.pyc", line 16, in <module>
  File "visa.pyc", line 1, in <module>
  File "pyvisa\visa.pyc", line 231, in <module>
  File "pyvisa\vpp43.pyc", line 105, in __new__
  File "pyvisa\visa.pyc", line 227, in init
  File "pyvisa\vpp43.pyc", line 758, in open_default_resource_manager
  File "pyvisa\vpp43.pyc", line 175, in __call__
  File "pyvisa\vpp43.pyc", line 141, in load_library
  File "ctypes\__init__.pyc", line 432, in __getattr__
  File "ctypes\__init__.pyc", line 362, in __init__
WindowsError: [Error 126] The specified module could not be found

具体来说,查看vpp43.pyc文件的第141行,表明该代码正在尝试使用ctypes windll模块加载Visa32.dll:

...
136 if os.name == 'nt':
137     if path:
138         self.__lib       = windll.LoadLibrary(path)
139         self.__cdecl_lib = cdll.LoadLibrary(path)
140     else:
141         self.__lib       = windll.visa32
142         self.__cdecl_lib = cdll.visa32
...

但是,即使我将此dll文件放在目标计算机上的System32文件夹中(与开发计算机上的位置相同),仍然会出现错误。

当前,我的py2exe设置文件如下:

from distutils.core import setup
import py2exe
import sys

sGUIPath = 'C:\\SVN_Files\\Design\\P0045_ZPower\\trunk\\30_Validation\\TestScripts\\GenericInstrControls\\Tabbed_GUI\\'
sHWPath = 'C:\\SVN_Files\\Design\\P0001_Design_Flow\\trunk\\30_Validation\\python\\gui\\'
sI2CPath = 'C:\\SVN_Files\\Design\\P0045_ZPower\\trunk\\30_Validation\\TestScripts\\GenericInstrControls\\Comm-I2C\\'
sOWTPath = 'C:\\SVN_Files\\Design\\P0045_ZPower\\trunk\\30_Validation\\TestScripts\\GenericInstrControls\\Comm-OWT\\'

aRegFiles = ['bronco_regs.csv', 'eeprom_regs.csv', 'tdv26_regs.csv']
aIncludes = ['communication', 'equipment', 'manual', 'tab_wrapper', 'hwcontrol', 'i2ccomm', 'owtcomm']

sys.path.append(sGUIPath)
sys.path.append(sHWPath)
sys.path.append(sI2CPath)
sys.path.append(sOWTPath)      

setup(
    windows = ['<company_name>_gui.pyw'],
    data_files = [('icon', [sGUIPath + 'Logo_Red_32x32.ico']),
        ('regfiles', [sGUIPath + sFile for sFile in aRegFiles]),
        ('serial', [sI2CPath + sFile for sFile in ['libMPSSE.dll', 'libMPSSE_i2c.h']])],
    options = {
        'py2exe': {
            'includes' : aIncludes
        }
    }
)

另外,如果我将+ ['pyvisa']显式添加到'includes'选项,则会出现相同的错误。

我是否真的需要在目标机器上安装pyvisa,还是我还缺少其他东西?

谢谢!

0 个答案:

没有答案