pythoncom is windows specific, so I skipped it. I have no idea if this is critical (if it were, using dwsim from python under linux would be a no-go area...)
So my test script looks like this:
#! /usr/bin/python3importclrimportsysimportglobfromSystem.IOimportDirectory,Path,Filedwsimpath="/usr/local/lib/dwsim/"# Add all dllsfordllinglob.glob(dwsimpath+"*.dll"):try:clr.AddReference(dll)print("Added reference to %s"%dll)exceptBaseExceptionase:print("Could not add reference to %s (invalid image?)"%dll)importDWSIM.Automation# Results in: System.NullReferenceException: Object reference not set to an instance of an objectinterf=DWSIM.Automation.Automation2()
Running it produces the following output:
[lots of lines concerned with references to dlls]Initializing DWSIM Automation Interface...APP CRASH!!!System.IndexOutOfRangeException: Index was outside the bounds of the array.at Gtk.Application.SetPrgname () [0x00005] in <91487213bf394f4aaf87012594abed2f>:0 at Gtk.Application.do_init (System.String progname, System.String[]& args, System.Boolean check) [0x00000] in <91487213bf394f4aaf87012594abed2f>:0 at Gtk.Application.InitCheck (System.String progname, System.String[]& args) [0x00000] in <91487213bf394f4aaf87012594abed2f>:0 at Eto.GtkSharp.Helper.Init () [0x00007] in <2084ba8256c9420ea60ad1e5f1df14e5>:0 at Eto.GtkSharp.Forms.ApplicationHandler.Initialize () [0x00006] in <2084ba8256c9420ea60ad1e5f1df14e5>:0 at Eto.WidgetHandler`1[TWidget].Eto.Widget.IHandler.Initialize () [0x00000] in <23bf6400f02d49eba883a8238fbdb959>:0 at Eto.Widget.Initialize () [0x0000a] in <23bf6400f02d49eba883a8238fbdb959>:0 at Eto.Widget..ctor () [0x00099] in <23bf6400f02d49eba883a8238fbdb959>:0 at Eto.Forms.Application..ctor (Eto.Forms.Application+InitHelper init) [0x00016] in <23bf6400f02d49eba883a8238fbdb959>:0 at Eto.Forms.Application..ctor (Eto.Platform platform) [0x00007] in <23bf6400f02d49eba883a8238fbdb959>:0 at DWSIM.UI.Desktop.Program.MainApp (System.String[] args) [0x00531] in <fc86f5821461452cb699997cb9ceb6e9>:0 Traceback (most recent call last):File "./processSimulation/00_pythonScripting/./runDWSim.py", line 21, in <module>interf=DWSIM.Automation.Automation2()System.NullReferenceException: Object reference not set to an instance of an objectat DWSIM.Automation.Automation2..ctor () [0x0003a] in <f5f021e4dcfa42b2bd8b0e4b0d93a743>:0 at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00008] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
For running the resulting dwsimtest.exe, I need to
exportMONO_PATH=/usr/local/lib/dwsim
From this, I think that:
1. Generally, mono etc. do work and I am able to create an Automation2 instance from c# code
2. This does not work from python code.
So, what might be the problem? Is it my installation of python-3.9.2? A bug? Incompatible mono version?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In your Documents/DWSIM Application Data folder, open dwsim_newui.ini and change the Linux renderer in [PlatformRenderers] from Gtk2 to WinForms. This will render DWSIM unusable in GUI mode, but gets Automation mode working.
There are some problems with setting flowsheet object properties from python, as they seem to have no effect. I'm investigating this.
Regards
Daniel
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2022-05-04
Hi Daniel,
thank you for your quick reply. I have been partially successful!
The installed mono version is Mono JIT compiler version 6.8.0.105 (Debian 6.8.0.105+dfsg-3.2 Tue Jun 29 21:01:01 UTC 2021),
I uninstalled pythonnet-3.0.0-dev1 and installed version 3.0.0a2
Changed the platformRenderer for Linux to WinForms
I was able to run both my testing script and your example.
1. My testing script (which does not do anything yet) segfaulted after successfully creating the Automation2 object
2. Your example crashed upon saving the flowsheet:
I am trying to get Automation2 to work under linux (Debian 11) from python (3.9.2), but I keep running into
The new GUI works ok on my machine, the classic UI crashes, if that's any help.
I started from here: https://gist.github.com/DanWBR/c355fd5420d20d960f5d084a7142cde8
pythoncom is windows specific, so I skipped it. I have no idea if this is critical (if it were, using dwsim from python under linux would be a no-go area...)
So my test script looks like this:
Running it produces the following output:
Note the nullptr in
There are a couple of topics related to this, but no solution is available as of today:
Only occurs when trying to create a second instance: https://sourceforge.net/p/dwsim/discussion/scripting/thread/c84c1f2adb/
Unresolved, user switched to c#: https://sourceforge.net/p/dwsim/discussion/linux_newui/thread/c473d78387/
I put together a small c# example, and that works (as in "does NOT crash"):
Under linux, I compile it with the following makefile:
For running the resulting dwsimtest.exe, I need to
From this, I think that:
1. Generally, mono etc. do work and I am able to create an Automation2 instance from c# code
2. This does not work from python code.
So, what might be the problem? Is it my installation of python-3.9.2? A bug? Incompatible mono version?
Hi Jordi,
This code works on Linux: https://gist.github.com/DanWBR/55cba7856f12cdde92a9e3a87f5194b9
It works with mono 6.8 but crashes with 6.12.
You must install this version of Python.NET: https://pypi.org/project/pythonnet/3.0.0a2/
In your Documents/DWSIM Application Data folder, open dwsim_newui.ini and change the Linux renderer in [PlatformRenderers] from Gtk2 to WinForms. This will render DWSIM unusable in GUI mode, but gets Automation mode working.
There are some problems with setting flowsheet object properties from python, as they seem to have no effect. I'm investigating this.
Regards
Daniel
Hi Daniel,
thank you for your quick reply. I have been partially successful!
Mono JIT compiler version 6.8.0.105 (Debian 6.8.0.105+dfsg-3.2 Tue Jun 29 21:01:01 UTC 2021)
,I was able to run both my testing script and your example.
1. My testing script (which does not do anything yet) segfaulted after successfully creating the Automation2 object
2. Your example crashed upon saving the flowsheet:
Without saving the flowsheet, it wrote the png file to my Desktop folder and then segfaulted like my script did.
I think I should be able to work with this as it is now. Any idea about the flowsheet saving crash?
The crash issue was fixed in DWSIM 7.5.5, Jordy.
Excellent, now everything runs fine! Both scripts still segfault at the end, but that does not hamper my progress.
I was not aware of version 7.5.5 because the Download button still takes us to 7.5.1.
Anyway, thank you very much! If you ever come to Cologne, I'd like to buy you a beer or three.