question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pyqt, matplotlib, multiprocessing comaptibility in windows

See original GitHub issue

Environment

  • Pythonnet version: 2.3
  • Python version: 3.6
  • Operating System: windows 10

Details

  • Describe what you were trying to get done.

    I used the console example code in the pythonnet, and modified it a little bit to test the capabilities. Please see the code below:

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Python.Runtime;

namespace Python.Runtime
{
    /// <summary>
    /// Example of Embedding Python inside of a .NET program.
    /// </summary>
    /// <remarks>
    /// It has similar functionality to doing `import clr` from within Python, but this does it
    /// the other way around; That is, it loads Python inside of .NET program.
    /// See https://github.com/pythonnet/pythonnet/issues/358 for more info.
    /// </remarks>
    public sealed class PythonConsole
    {
        static void Main(string[] args)
        {
            using (Py.GIL())
            {
                dynamic np = Py.Import("numpy");
                dynamic plt = Py.Import("matplotlib.pyplot");
                dynamic exp = Py.Import("pyqtgraph.examples");
                Console.WriteLine(np.cos(np.pi * 2));
                plt.plot(np.cos(np.pi * 2));
                exp.run();

                dynamic mp = Py.Import("ProcessIDTest");
                Console.WriteLine(2);
                mp.main();

                Console.WriteLine(3);
            }
        }
    }
}

Also the python code named ProcessIDTest.py:

from multiprocessing import Process
import os, time
def f(name):
	print('Inside f.')
    #plt.plot([1,2]);
    #plt.show();

def main():
    for i in range(2):
        p = Process(target=f, args=('bob' +str(i),));
        #p.start();
        #p.join()
    print('Main function executed.')
    
if __name__ == '__main__':
    #main();
  • What commands did you run to trigger this issue? If you can provide a If you run the code directly in vs2017, the following error was given, which is related to pyqt.
This application failed to start because it could not find or load the Qt platform plugin "windows"
in "". Reinstalling the application may fix this problem. 
Fatal Python error: auto-releasing thread-state, but no thread-state for this thread. 

I already tried reinstall my python and it’s still the same problem. Also I tested all the matplotlib backends, with only TkAgg working fine. Pyqt, tested with pyqtgraph, aslo did n’t work in PythonEngine as well. The same error was produced.

I also tested the multiprocessing in embedded python. If I start a child process, it will basically make my c# program looping, with more and more nPython.exe spawned. If you do not start it, everything works fine (like the code below).

for i in range(2):
p = Process(target=f, args=('bob' +str(i),));
#p.start();
#p.join()

For my project, what I need are the following packages: pyqt, matplotlib, pydaqmx, multiprocessing, pyglet. If you could let me know any news related to their compatibility, that would be awesome.

THANK YOU SO MUCH!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
denfromufacommented, Mar 2, 2018

@neurochen can you format your code according to github markdown?

0reactions
bakulevcommented, Jan 14, 2020

@neurochen sorry for offtopic. I don’t know how to contact with you by other way. Could you add me in http://github.com/thorlabs , please?

Read more comments on GitHub >

github_iconTop Results From Across the Web

PyQt MainWindow using multiprocessing on Windows
I try to create a PyQt application. In order to run process in background and keep the PyQt5 application available for new instruction,...
Read more >
Embedding in Qt — Matplotlib 3.7.2 documentation
Simple Qt application embedding Matplotlib canvases. This program will work equally well using any Qt binding (PyQt6, PySide6, PyQt5, PySide2). The binding can ......
Read more >
PySimpleGUI
It's surprising that Python GUI code is completely cross platform from Windows to Mac to Linux. No source code changes. This is true...
Read more >
PyQtGraph - Scientific Graphics and GUI Library for Python
PyQtGraph is a pure-python graphics and GUI library built on PyQt / PySide ... Multi-process control allowing remote plotting, Qt signal connection across ......
Read more >
Differences between multiprocessing on Windows and Linux
Multiprocessing behaves very differently on Windows and Linux. Learn the differences to prevent mistakes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found