0

This question already has an answer here:

I am in my first steps in PyQt5. I intend to create a plugin within QGis 3.0. I would like to convert the file resources.qrc into py file, by running windows shell commands with python. However, when I execute:

pyrcc4 resources.qrc -o resources.py

The code of resources.qrc is as follow:

<RCC>
 <qresource prefix="/">
  <file>://Program Files/QGIS3.2/apps/qgis/python/plugins/testPlugin/icon.png</file>
 </qresource>
</RCC>

The code of testPlugin.py is as follow:

from PyQt5.QtCore import *
from PyQt5.QtGui import *
import resources

class TestPlugin:
 def __init__(self, iface):
   self.iface = iface

 def initGui(self):
   self.action = QAction("Run", self.iface.mainWindow())
   QObject.connect(self.action, SIGNAL("triggered()"),self.onRun)
   self.iface.addPluginToMenu("Test Plugin", self.action)

 def unload(self):
   self.iface.removePluginMenu("Test Plugin", self.action)

 def onRun(self):
   QMessageBox.information(self.iface.mainWindow(), "debug","Running")

enter image description here I receive the following message error: invalid syntax. I verify the path files, but without success. enter image description here

When I execude the code from Windows commande, pyrcc4 is not recognized as internal or external command, executal program or command file.

enter image description here

Any help is welcome.

marked as duplicate by underdark Mar 2 at 9:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

You are running a system command from a Python prompt. On Windows you'd want to be running it from the C:\> prompt of a command window.

You may have to give the full path to pyrcc4 if you have not configured Windows to look in the right place.

To be totally clear, here is me trying to run pyrcc4 from the python interpreter:

Python 2.7.14 (default, Sep 23 2017, 22:06:14) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> pyrcc4 foo.qrc -o foo.py
  File "<stdin>", line 1
    pyrcc4 foo.qrc -o foo.py
             ^
SyntaxError: invalid syntax

Same error as you. One does not run pyrcc4 from the Python interpreter - you run it from the command line. Here I am running it from the Linux command line - notice the prompt is "$"

$ pyrcc4 foo.qrc -o foo.py
pyrcc4: File does not exist 'foo.qrc'

Notice the different error - pyrcc4 is running, and not finding the qrc file I mentioned. In your case, if you get this right, it should find it and create the python file.

  • I add a capture of Python prompt where I execute the code with file full path, but with no success. – ennine Aug 19 '18 at 17:00
  • Thank you Spacedman for your quick response. I am sorry to ask you again: how to configure Windows to look into the right place? – ennine Aug 19 '18 at 20:35
  • Edit your question to show what happens when you try and run it from the Windows command prompt. – Spacedman Aug 19 '18 at 20:48
  • I edit my question above. When I execude the code from Windows commande, pyrcc4 is not recognized as internal or external command, executal program or command file. As you mentioned, I did not configure Windows to find the right path to pyrrc4. – ennine Aug 19 '18 at 21:31

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