PyQt5 pyuic module error

2019-07-29 09:45发布

问题:

I'm tryng to convert some .ui file into .py. I looked all over the internet for some tutorials and none seem to work for me, pyuic.bat is not found anywere un mi pc, and if i run

python pyuic.py -o file.py file.ui

i always get some errors like:

file "pyuic.py", line 28, in module
    from .diver import Diver
Valuerror: Attempted relative import in non-package

i'm using python 2.7 on windows 10, and PyQt 5.6.

回答1:

You might not have the pyuic5.bat file depending on how you installed PyQt5. But you can make one easily enough. Just create a file named pyuic5.bat and place it in your PyQt5 directory e.g. C:\python-qt5\PyQt5), and have the file contain:

python -m PyQt5.uic.pyuic %*

This requires that:

  • Your PyQt5 directory is listed in your PYTHONPATH, e.g. C:\python-qt5,
  • The directory containing pyuic5.bat is listed in PATH, e.g. C:\python-qt5\PyQt5.