Menu

TypeError when using Python.NET in combination with "print()"

Linus
2020-08-28
2020-09-14
  • Linus

    Linus - 2020-08-28

    Hi Daniel and Forum,

    I'm trying to implement a reactor with a kinetic model which I implemented using scipy. Everything works fine until the solver (fmin_slsqp) trys to display its results by using the print command, which results in the following error message:

    TypeError : a bytes-like object is required, not 'str'

    which causes the script to stop. I can replicate the problem (DWSIM v6.1u4 & WPy 3.7.7) by simply using the print command and choosing Python.NET as an interpreter.

    As a workaround, overloading the print function works locally, but does not carry over to the solver. Another way is to disable the solver output, which causes it to skip the print statements. Both are obviously not ideal solutions.

    It's propably a really simple fix, I just can't figure it out - any help would be appreciated!

    Best Regards
    Linus

     
  • Daniel Medeiros

    Daniel Medeiros - 2020-08-28

    perhaps you could try modifying the print() call directly in the solver code, is that possible?

     
  • Linus

    Linus - 2020-08-28

    Thanks for the quick reply! That would propably be possible, but it's still a workaround. As for now, the two workarounds which i mentioned earlier work as well, so the problem is not a showstopper. I just hoped you could help me identify the cause of the problem so I could implement a clean solution.

     
  • Daniel Medeiros

    Daniel Medeiros - 2020-08-28

    Actually I also face this issue very often. Perhaps it is something withe Python.NET library. I'll take a look.

     
  • Linus

    Linus - 2020-08-28

    Glad to know I'm not the only one. Thanks for looking into it!

     
  • Daniel Medeiros

    Daniel Medeiros - 2020-08-28

    Is your scipy module in the latest version?

     
  • Linus

    Linus - 2020-09-14

    Sorry for the late reply, I've been out of town for the last two weeks. I'm using scipy 1.4.1, which was included in WinPython 3.771.

     
  • Daniel Medeiros

    Daniel Medeiros - 2020-09-14

    Is it possible to override the function globally? I have no idea how to fix it since it is not a problem with DWSIM itself...

     
  • Linus

    Linus - 2020-09-14

    I've been trying this as well for a few hours but can't get it to work. It might be possible, but I'm not a python expert by any means. I'll just stick to the workaround for now.

    Thanks for your help!

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.