unable to import shiboken2

1.9k views Asked by At

I'm trying to embedding PySide2 into a C++ program. The main program links with the Python lib and use PyRun_SimpleFile to execute a Python script file, which are about some Qt PySide2 stuff. It works fine when the main program is built in release mode (link with python38.lib), but cannot work in debug build (link with python38_d.lib), because PyRun_SimpleFile failed. Error messages:

PySide2/__init__.py: Unable to import shiboken2 from E:\workspace\qide\qide\src\app\exp\py, C:\dev\Python\Python38\python38_d.zip, C:\dev\Python\Python38\DLLs, C:\dev\Python\Python38\lib, C:\dev\Python\Python38, C:\dev\Python\Python38\lib\site-packages
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    from PySide2.QtWidgets import QApplication, QPushButton, QMessageBox, QDialog
  File "C:\dev\Python\Python38\lib\site-packages\PySide2\__init__.py", line 107, in <module>
    _setupQtDirectories()
  File "C:\dev\Python\Python38\lib\site-packages\PySide2\__init__.py", line 58, in _setupQtDirectories
    import shiboken2
  File "C:\dev\Python\Python38\lib\site-packages\shiboken2\__init__.py", line 27, in <module>
    from .shiboken2 import *
ModuleNotFoundError: No module named 'shiboken2.shiboken2'

The error is from a line:

from PySide2.QtWidgets import QApplication, QPushButton, QMessageBox, QDialog

It seems that Python cannot import shiboken2 with debug library (python38_d.lib).

I got the same error messages when I run the same script via Python's debug executable directly: python_d test.py, while python test.py works fine, just like my main program in release build.

Any ideas?

My Environment:

  • Windows10
  • Python3.8 (with debug binary installed)
  • Visual Studio 2019
0

There are 0 answers