How can you easily select between PyQt or PySide at runtime?

后端 未结 3 1346
长发绾君心
长发绾君心 2021-01-13 06:58

I would like to do something like this in one source file, QT.py:

import sys
import PyQt4

sys.modules[\"Qt\"] = PyQt4

Then import this fil

3条回答
  •  生来不讨喜
    2021-01-13 07:14

    You can conditionally import libraries. Here is a bit of a hacky example, where you check for a command-line argument of "PyQt4":

    import sys
    
    if sys.argv[-1] == 'PyQt4':
        import PyQt4
        sys.modules["Qt"] = PyQt4
    else:
        import Qt
        from Qt.QtCore import *
    

提交回复
热议问题