g-sherman / plugin_build_tool

Python command line tool for compiling and deploying QGIS plugins
GNU General Public License v2.0
38 stars 18 forks source link

Deploy fails to compile resources #20

Open peetw opened 3 years ago

peetw commented 3 years ago

After creating a new plugin on Windows, pb_tool deploy fails to compile the resources.qrc file and thus fails to deploy the plugin. This can be fixed by running pb_tool compile (which does succeed) first.

Steps to reproduce

Open a PyQGIS-enabled command prompt and run the following commands:

pb_tool create --modulename test_plugin --classname TestPlugin --menutext "Test plugin..."
pb_tool deploy -y

This will output the following:

Deploying to C:/Users/Peet/AppData/Roaming\QGIS/QGIS3/profiles/default/python/plugins\test_plugin
Removing plugin from C:/Users/Peet/AppData/Roaming\QGIS/QGIS3/profiles/default/python/plugins\test_plugin
Plugin was not deleted: The system cannot find the path specified
Deploying to C:/Users/Peet/AppData/Roaming\QGIS/QGIS3/profiles/default/python/plugins\test_plugin
Compiling to make sure install is clean
Compiled 0 UI files
Compiling resources.qrc to resources.py
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00006940 (most recent call first):
Traceback (most recent call last):
  File "C:\OSGEO4~1\apps\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\OSGEO4~1\apps\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\OSGEO4~1\apps\Python37\Scripts\pb_tool.exe\__main__.py", line 7, in <module>
  File "C:\OSGEO4~1\apps\Python37\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "C:\OSGEO4~1\apps\Python37\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "C:\OSGEO4~1\apps\Python37\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\OSGEO4~1\apps\Python37\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\OSGEO4~1\apps\Python37\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\OSGEO4~1\apps\Python37\lib\site-packages\pb_tool\pb_tool.py", line 121, in deploy
    deploy_files(config_file, plugin_path, user_profile, quick=quick, confirm=not no_confirm)
  File "C:\OSGEO4~1\apps\Python37\lib\site-packages\pb_tool\pb_tool.py", line 170, in deploy_files
    compile_files(cfg)
  File "C:\OSGEO4~1\apps\Python37\lib\site-packages\pb_tool\pb_tool.py", line 996, in compile_files
    subprocess.check_call([pyrcc5, '-o', output, res])
  File "C:\OSGEO4~1\apps\Python37\lib\subprocess.py", line 328, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['C:\\OSGEO4~1\\apps\\Python37\\Scripts\\pyrcc5.BAT', '-o', 'resources.py', 'resources.qrc']' returned non-zero exit status 3221226505.

System

dortegat commented 3 years ago

I think the problem is related to the path space of QGIS xx. See this link .

The problem is that when you change it directly to double quotes, the Python statement in pb_tool treats it as single quotes.

Command '['C:\\PROGRA~1\\QGIS 3.10\\apps\\Python37\\Scripts\\pyrcc5.BAT', '-o', 'resources.py', 'resources.qrc']'

C:\Program Files\QGIS 3.10\apps\Python37\Scripts\pyrcc5.bat

@C:\\PROGRA~1\\QGIS 3.10\apps\Python37\python.exe -m PyQt5.pyrcc_main %*
@"C:\\PROGRA~1\\QGIS 3.10\apps\Python37\python.exe" -m PyQt5.pyrcc_main %*

On the other hand, it is giving me an error building the documentation:

Building the help documentation
"sphinx-build" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
peetw commented 3 years ago

@dortegat I'm not sure that is the issue here - I installed QGIS using OSGeo4W, which by default installs to C:\OSGeo4W64 and has no spaces in the path (see Command '['C:\\OSGEO4~1\\apps\\Python37\\Scripts\\pyrcc5.BAT', '-o', 'resources.py', 'resources.qrc']'). Furthermore, running pb_tool compile works correctly, it's just pb_tool deploy that fails to compile.

dortegat commented 3 years ago

@peetw In my case I installed QGIS version 3.10 standalone.

Compiling the resource file without pb_tool, the following code works correctly editing the file adding the double quotes (C:\Program Files\QGIS 3.10\apps\Python37\Scripts\pyrcc5.bat):

SET OSGEO4W_ROOT = C: \ Program Files \ QGIS 3.10
call "% OSGEO4W_ROOT%" \ bin \ o4w_env.bat
call qt5_env.bat
call py3_env.bat
pyrcc5 -o resources.py resources.qrc

If they are not added, it gives the following error:

"C:\\PROGRA~1\\QGIS" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
peetw commented 3 years ago

@dortegat Indeed, but that looks to be a separate issue to the one that I originally raised.

dortegat commented 3 years ago

Also I have the following error building the documentation with Sphinx

Building the help documentation
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00003c68 (most recent call first):