Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict with PyQT library #6174

Closed
zapaishchykova opened this issue Mar 31, 2020 · 7 comments
Closed

Conflict with PyQT library #6174

zapaishchykova opened this issue Mar 31, 2020 · 7 comments
Labels

Comments

@zapaishchykova
Copy link

Required Info
Operating System & Version Win 10
Platform PC
Language python

Issue Description

So my problem is that when librealsense.py ( ver.2) cannot be imported into the project with PyQT. I open my UI, and then just one simple pressing button stops the app completely. I didn't call any functions from libsense library, it's just simple:
import pyrealsense2 as rs
The more frustrating is that it doesn't show any error. Seems to be similar to the #4856 , but i don't get what means "import localy".
Also tried to build wrapper from wheel/ installing with pip install pyrealsense2, neither worked. Also tried building from source with this https://github.com/IntelRealSense/librealsense/blob/master/doc/installation_windows.md , but after building solution in VS I don't see any files in python wrapper folder so I gave up.
Any suggestions on how to tackle this issue will be much appreciated!

@dorodnic dorodnic added the python label Apr 1, 2020
@alaricLEA
Copy link

This sounds similar to the bug I reported. #6141. Importing the pyrealsense2 library (and not calling anything) causes issues with wxPython and Tkinter on Windows.

@RealSenseCustomerSupport
Copy link
Collaborator


@zapaishchykova What's the SDK version when you get the issue? And did you check if python examples in SDK package work normally? Looking forward to your update. Thanks!

@zapaishchykova
Copy link
Author

Hi! Yes, python samples work just fine, it all happens when such imports are present alongside with librealsence import:

from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtMultimediaWidgets import *
from PyQt5.QtMultimedia import *

I am using SDK 2.0 but as far as I understand it is not used while I import the package in Python?

@mareikethies
Copy link

mareikethies commented Apr 27, 2020

I faced a very similar issue and solved it by adding these lines before any other imports:

import sys
sys.coinit_flags = 2
import pythoncom

Now pyrealsense2 can be imported together with the PyQt5 components and opening further windows from the GUI works, too. @alaricLEA maybe you can find a useful hint for your issue, too.

This would be a minimal example which works with these additional lines, but breaks without them as soon as you try to open the file dialogue:

import sys
sys.coinit_flags = 2
import pythoncom
import pyrealsense2
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QFileDialog
from PyQt5.QtCore import pyqtSlot


class App(QWidget):

    def __init__(self):
        super().__init__()
        self.title = 'PyQt5 fail test'
        self.left = 10
        self.top = 10
        self.width = 320
        self.height = 200
        self.initUI()

    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        button = QPushButton('PyQt5 button', self)
        button.move(100, 70)
        button.clicked.connect(self.on_click)

        self.show()

    @pyqtSlot()
    def on_click(self):
        print('Start function on_click')
        filename, _ = QFileDialog.getOpenFileName(self, "QFileDialog.getOpenFileName()", "",
                                                 "All Files (*);;Python Files (*.py)")
        if filename:
            print(filename)

        print('End function on_click')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

@zapaishchykova
Copy link
Author

That works! Awesome, Thanks!!

@alaricLEA
Copy link

Works for me too. Many thanks!

@AkiraGiShinichi
Copy link

It works like a charm. Many thanks to @mareikethies !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants