0

I am trying to embed resources to my PyQt4 application.

However when I import the resource file that I create by using included pyrcc.exe I came accross encoding errors.

Pyrcc already adds the UTF-8 encoding line on top of the file as this was the common error I have seen online.

SyntaxError: Non-ASCII character '\xff' in file ... on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

As I have checked the error link it recommends to add encoding line to the file which I already have

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Resource object code
#
# Created: Mon Sep 14 10:40:57 2015
#      by: The Resource Compiler for PyQt (Qt v4.8.6)
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore

qt_resource_data = "\
\x00\x00\x06\xdf\
\x89\
\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\
\x00\x00\x40\x00\x00\x00\x40\x08\x06\x00\x00\x00\xaa\x69\x71\xde\
\x00\x00\x06\xa6\x49\x44\x41\x54\x78\x5e\xed\x5b\x5d\x72\xda\x48\...

Any suggestions would be appreciated. Thanks !

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • Suggestion: post the **complete, unedited error message** you get when trying to import the resource. – ekhumoro Sep 14 '15 at 12:34
  • `...on line 1`? That wouldn't match the file you've posted. Are you sure it's not complaining about a different file? – mata Sep 14 '15 at 12:59
  • `Traceback (most recent call last): File "C:/Users/enes.caylak/PycharmProjects/v2/batch_2", line 16, in from qtdesigner import Ui_MainWindow File "C:\Users\enes.caylak\PycharmProjects\v2\qtdesigner.py", line 732, in import resource2_rcFile "C:\Users\enes.caylak\PycharmProjects\v2\resource2_rc.py", line 1 SyntaxError: Non-ASCII character '\xff' in file C:\Users\enes.caylak\PycharmProjects\v2\resource2_rc.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details Process finished with exit code 1` – Enes Çaylak Sep 15 '15 at 06:09
  • This is the complete error I get. The content of resource2_rc.py is as given above. So I dont think that its complaining about a different file. – Enes Çaylak Sep 15 '15 at 06:14
  • @EnesÇaylak. The `\xff` looks like part of the [byte order mark](https://en.wikipedia.org/wiki/Byte_order_mark) for UTF-16. Have you (or the code editor you're using) changed the encoding of the resource file? It obviously should be encoded as UTF-8 (which is what `pyrcc` will output). – ekhumoro Sep 15 '15 at 16:23

0 Answers0