8

I tried to transpose the QGIS 2 process with no success.

I first had to edit C:\Program Files\QGIS 2.99\etc\ini\python-core.bat which contains references to Python27 instead of Python36.

I run C:\Program Files\QGIS 2.99\bin\o4w_env.bat to properly configure QGIS python environment, but then, when I launch :

"C:\Program Files\QGIS 2.99\apps\Python36\Scripts\pyuic5.bat" -o dockwidget_base.py dockwidget_base.ui

I get this error :

Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS2~1.99\apps\Python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\PROGRA~1\QGIS2~1.99\apps\Python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\PROGRA~1\QGIS2~1.99\apps\Python36\lib\site-packages\PyQt5\uic\pyuic.py", line 26, in <module>
    from PyQt5 import QtCore
ImportError: DLL load failed: Specified module could not be found.

Similarly, when I launch :

"C:\Program Files\QGIS 2.99\apps\Python36\Scripts\pyrcc5.bat" -o resources_rc.py resources.qrc

I get this error :

Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS2~1.99\apps\Python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\PROGRA~1\QGIS2~1.99\apps\Python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\PROGRA~1\QGIS2~1.99\apps\Python36\lib\site-packages\PyQt5\pyrcc_main.py", line 21, in <module>
    from PyQt5.QtCore import PYQT_VERSION_STR, QDir, QFile
ImportError: DLL load failed: Specified module could not be found.
11

You need set PyQT5 environments. This is my scripts for compile QGIS 3 Plugins and have 3 complementary bats.

compile_ui.bat

@ECHO OFF

set OSGEO4W_ROOT=D:\OSGeo4W64

set PATH=%OSGEO4W_ROOT%\bin;%PATH%
set PATH=%PATH%;%OSGEO4W_ROOT%\apps\qgis\bin

@echo off
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
call "%OSGEO4W_ROOT%\bin\py3_env.bat"
@echo off
path %OSGEO4W_ROOT%\apps\qgis-dev\bin;%OSGEO4W_ROOT%\apps\grass\grass-7.2.2\lib;%OSGEO4W_ROOT%\apps\grass\grass-7.2.2\bin;%PATH%

cd /d %~dp0

@ECHO ON
::Ui Compilation
call pyuic5 dialog.ui -o gui\generated\ui_dialog.py          

::Resources
call pyrcc5 ui\resources.qrc -o gui\generated\resources_rc.py

@ECHO OFF
GOTO END

:ERROR
   echo "Failed!"
   set ERRORLEVEL=%ERRORLEVEL%
   pause

:END
@ECHO ON

You only need change set OSGEO4W_ROOT=D:\OSGeo4W64 for set OSGEO4W_ROOT="C:\Program Files\QGIS 2.99", or something like that,

Try using this .bat

Note: this bat is in the same folder as the plugin

Note 2 : For import import resources_rc need this trick

call pyuic5 --import-from <package-name>.gui.generated dialog.ui -o gui\generated\ui_dialog.py`

this path probably change in other plugin. pyuic5

@sigeal soluton for Note 2 :

call pyuic5 dockwidget_base.ui --from-imports -o dockwidget_base.py

I hope it helps

  • 1
    Great answer, that's exactly what I was looking for. Thanks. – sigeal Nov 6 '17 at 18:29
  • One question though : "import resources_rc" at the end of generated file gives me a "No module named 'resources_rc'" error. I can get rid of this error with "from . import resources_rc" but this is not a correct solution as the file is generated... Do I miss something ? – sigeal Nov 6 '17 at 18:51
  • 1
    Ok you need add this call pyuic5 --import-from <package-name>.gui.generated. Need put the path for your resource file and compile again. – Fran Raga Nov 6 '17 at 19:00
  • 1
    I ended with this command call pyuic5 dockwidget_base.ui --from-imports -o dockwidget_base.py. It works perfectly. – sigeal Nov 6 '17 at 19:21
  • 1
    Update my answer with your solution – Fran Raga Nov 6 '17 at 19:22
2

After having found out everything about the environment variables and knowing what I was searching for, I found the file /osgeo4w_root/bin/python-qgis-dev.bat

When called from the active osgeo4w shell, it sets all the env. variables by calling the corresponding .bat files (as suggested by Francisco)!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.