"进口CLR"精编与cx_freeze后的问题问题、QUOT、CLR、cx_freeze

2023-09-04 00:46:53 作者:Krismile(微笑)

我有一个进口CLR 崩溃的一个问题,我的小程序。的.exe

下面是我用的是进口在我的计划:

 进口SYS
从matplotlib.figure导入图
从matplotlib.backends.backend_qt4agg进口FigureCanvasQTAgg为FigureCanvas
从PyQt4.QtGui进口的QApplication,QMainWindow的
从PyQt4.Qt进口QGridLayout,QWidget的
进口CLR
executablePath ='E:\\ PythonWS \\ MYDLL \\
sys.path.append(executablePath)
clr.AddReference(MYDLL)
进口MYDLL
 

基本程序编译罚款,我得到一个可执行感谢cx_freeze,但是当我启动它与日志,它崩溃来的时候进口CLR

我不知道该怎么办,使其工作,如果任何人有一个想法?

编辑: 我加了一个尝试 - 除了周围的进口CLR 是这样的:

 相关搜索:
    logger.info('中试')
    进口CLR
    executablePath ='E:\\ PythonWS \\ MYDLL \\
    sys.path.append(executablePath)
    clr.AddReference(MYDLL)
    DllPath的= clr.FindAssembly('MYDLL)
    进口MYDLL
    TS = MyDll.TestSystem(127.0.0.1,127.0.0.1)
    打印ts.mainBoard.isConnected()
除了异常为e:
    logger.info(意外的错误:{}。格式(E))
 
019马自达CX 3评语 很好东西,但他是小包装的精制产品

不过,即使有尝试的参加办法崩溃......这使我有2个选项,

无论是我的尝试 除了是不好的,然后点击 在没有与 CLR 一个真正的问题,我需要帮助一下吧。

EDIT2:

我想进口想这可能是该的.exe 无法找到其他模块,从 .pyd 他们,但所有的进口我已经试过,没有任何问题都做了。

EDIT3:

这样的!看后在其他文章中,我已经看到了,有要导入的dll其他方法:使用 ctypes的例如:

但问题是:我的DLL是 C#,显然进口不支持有出色的 ctypes的 ..我得到了像错误WindowsError:[错误-532462766] Windows错误0xE0434352 这并没有帮助我很多,因为它似乎是在windows一个非常普遍的错误,但是这却让我想也许这让我当导入CLR是一样的..有谁知道什么可能错误涉及到?

程序崩溃的东西

于是我回使用.NET CLR ,但仍没有运气

有关记录:我曾经尝试都蟒蛇32位和64位。这里有一些更多的信息

  #with蟒蛇32位
平台架构:(32位,windowsPE的)
sys.platform:Win32的
os.name:NT

#with蟒蛇64位
平台架构:('64','windowsPE的)
sys.platform:Win32的
os.name:NT
 

解决方案

所以,我最终取得了它的工作:

在最后,pythonNET已正确安装,但它似乎版本是不是最好的(不知道,如果不是最新的,或不正确的版本,或位),所以我删除pythonNET的每个文件(我有复制粘贴在这里和那里,以确保它被认为),并下载了 .whl (这里)(这是不是一个 PIP 正在下载)。

和最终的进口CLR 工作

我希望这有助于你们中的一些:)

I have a problem with import clr that crashes the .exe of my small program.

Here are the imports I use in my program:

import sys
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from PyQt4.QtGui import QApplication, QMainWindow
from PyQt4.Qt import QGridLayout, QWidget
import clr
executablePath = 'E:\\PythonWS\\MyDll\\'
sys.path.append(executablePath)
clr.AddReference("MyDll")
import MyDll

Basically the program compile fine and I get an executable thanks to cx_freeze, but when I launch it with a log, it crashes when comes import clr

I don't know what to do to make it work, if anyone has an idea?

EDIT: I added a try-except around the import clr like this:

try:
    logger.info('in try')
    import clr
    executablePath = 'E:\\PythonWS\\MyDll\\'
    sys.path.append(executablePath)
    clr.AddReference("MyDll")
    dllPath = clr.FindAssembly('MyDll')
    import MyDll
    ts = MyDll.TestSystem('127.0.0.1', '127.0.0.1')
    print ts.mainBoard.isConnected()
except Exception as e:
    logger.info("Unexpected error: {}".format(e))

But even with the try the appplication crashes... That leads me with 2 options,

either my try except isn't good and then why? there is a real problem with clr and I need help about it.

EDIT2:

I tried importing other module that are from .pyd thinking it might be that the .exe could not find them but all the import I've tried were done without any problem.

EDIT3:

SO! After looking on other posts, I've seen that there were other ways to import dll: by using ctypes for example.

Problem is: my dll is in C# and apparently the import is not supported very well by ctypes... I got errors like WindowsError: [Error -532462766] Windows Error 0xE0434352 which did not help me much since it seems to be a very general error in windows, but this made me think maybe the thing that makes my program crash when importing clr is the same.. Does anyone know what could the error be related to?

So I am back to using .NET clr, but still no luck

For the record: I have tried both python 32 bits and 64 bits. Here are some more information

#with python 32 bits
platform architecture:  ('32bit', 'WindowsPE') 
sys.platform:  win32
os.name:  nt

#with python 64 bits
platform architecture:  ('64bit', 'WindowsPE')
sys.platform:  win32
os.name:  nt

解决方案

So I eventually made it work:

In the end, pythonNET was installed correctly but it seems the version wasn't the best (not sure if not the latest, or not the right version, or bit), so I deleted every file of pythonNET (that I had copy-pasted here and there to be sure it was seen) and downloaded the .whl (here) of a latest version (which wasn't the one pip was downloading).

And eventually the import clr worked...

I hope this helps some of you :)