from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebKit import *
from PyQt5.QtWebKitWidgets import *
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow
import sys
import os
class Navigation(QWidget):
def __init__(self):
super().__init__()
self.web = QWebView()
self.web.settings().setAttribute(QWebSettings.
JavascriptEnabled,True)
#self.web.settings().setAttribute(QWebSettings.
# JavascriptCanOpenWindows, True)
self.web.settings().setAttribute(QWebSettings.
JSAC, True)
#self.web.settings().setAttribute(QWebSettings.
#DeveloperExtrasEnabled, True)
filepath = os.path.join(
os.path.dirname(__file__), 'MapSite.html')
self.web.show()
self.web.load(QUrl.fromLocalFile(filepath))
app = QApplication(sys.argv)
ex= Navigation()
app.exec_()
This PyQt program display a webpage only when run from IDLE for python3. When I run this program fom command line or make a Navigation class object by importing in other files, the webpage not displayed, just white screen
EDIT
pi@raspberrypi:~/RaspiCallSystem4 $ python3 navigation.py
libEGL warning: DRI2: failed to authenticate
qt5ct: using qt5ct plugin
qt5ct: D-Bus system tray: no
when I execute from command line It give above output, web window starts but with white page only, running from IDLE executes smoothly

As the following answer indicates in some cases the command
os.path.dirname(__file__)can return an empty string, and that's the case of the terminal, so there are 2 possible solutions:Or: