2

I was trying to build this example:

https://www.linuxvoice.com/build-a-web-browser-with-20-lines-of-python/

I'll just repost it here for completeness:

from PyQt5.QtCore import QUrl 
from PyQt5.QtWidgets import QApplication 
from PyQt5.QtWebKitWidgets import QWebView 
import sys

app = QApplication(sys.argv) 
view = QWebView() 
view.show() 
view.setUrl(QUrl(“http://linuxvoice.com”)) 
app.exec()

I also used the indications here to install pyqt5

https://askubuntu.com/questions/612314/how-to-install-pyqt-for-python3-in-ubunt-14-10

and also installed Qt5. So I should have everything they say in the linuxvoice tutorial.

When I want to run this with python 2.7, it says:

 File "brows.py", line 9 SyntaxError: Non-ASCII character '\xe2' in file brows.py on line 9, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

and with Python3:

File "brows.py", line 9
view.setUrl(QUrl(“http://linuxvoice.com”)) 
SyntaxError: invalid character in identifier

Did anyone manage to make this work?

Community
  • 1
  • 1
Qubix
  • 4,161
  • 7
  • 36
  • 73
  • SOLVED: Basically I was missing these packages http://stackoverflow.com/questions/30734287/how-to-install-qtsvg-qtwebkit-qtwebkitwidgetsall-in-qt5-version-on-ubuntu-14-0 – Qubix Feb 08 '16 at 20:10

2 Answers2

3

SO here's the actual answer. I had the same issue and discovered it very fast. view.setUrl(QUrl(“http://linuxvoice.com”)) Notice that their code uses quotes, look at how the quotes are compared to normal quotes.

Normal: ""

Theirs: “”

Basically, they're using weird ASCII quotes that Python can't handle. Really sneaky way to prevent copy-pasters. Either way this code doesn't work anymore because in the most recent version of PyQt5, QtWebKitWidgets was removed.

trickytype
  • 66
  • 1
  • 8
0

You've got a stray byte somewhere in your code. It's popped up on StackOverflow previously and there's a good method for finding it: Python "SyntaxError: Non-ASCII character '\xe2' in file".

Community
  • 1
  • 1
Nicholas Smith
  • 11,642
  • 6
  • 37
  • 55
  • So I solve that, now both of them point to the http saying invalid character in identifier. – Qubix Feb 08 '16 at 12:07
  • Did you copy the code from elsewhere? If so it might have hidden webformatting bytes, try just deleting the line and recoding it from scratch. – Nicholas Smith Feb 08 '16 at 12:08
  • I rewrote everything. I still get: File "brows.py", line 10 app.exec() ^ SyntaxError: invalid syntax – Qubix Feb 08 '16 at 17:09
  • 1
    @Qubix. You need to use `app.exec_()` in pyqt, because `exec` is a keyword in python2. The non-ascii characters are the left/right double quotation marks (`“”`), which are often used in web pages rather than the standard double quotes (`"`). – ekhumoro Feb 08 '16 at 18:57