Cannot import anything from PyQt5 - python

I've successfully installed Python 3.5.1 and PyQt5. But as soon as I try to import anything from PyQt5, it fails like this:
import sys
from PyQt5.QtWidgets import QApplication, QWidget
File "stdn", line 1, in "module"
ImportError: Dll load failed: The specified module could not be found.
I've checked my PATH and everything is OK: I have both D:\Python3\Lib\site-packages\PyQt5 and D:\Python3\Lib\site-packages.
Python and PyQt5 are both 64-bit versions.
Path Printscreen:
This is a printscreen of my Environment variable Path

Related

pyinstaller "unable to find a txt file when adding a binary"

When i was converting my script to exe using pyinstaller i got an error:-
Unable to find "c:\users\praveen\appdata\local\programs\python\python36\lib\site-packages\importlib_resources\version.txt" when adding binary and data files
You can view the full error here:
https://drive.google.com/file/d/1FmV5kdb7p6TgEZwKBFDmFIszC-Qha0BD/view?usp=sharing
my script has alot of imports, they are:-
import tkinter as tk
import os
import time
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from PIL import ImageGrab
import numpy as np
import cv2
import pytesseract
import webview
what does that error mean? and why am i getting it?
You need to write the command correctly, example:
pyinstaller --add-data web_folder;web_folder --add-data db.sqlite;. gui.py
Description: title_of_folder_or_file;path_to_it (if your OS Windows use ";", else ":". On windows it's 100% but on linux or mac i don't know) for folder you need after ; set path to this folder, example web_folder;web_folder
Source - Official Documentation

when i run the exe i get No module named 'PyQt5' but from the script its work

i use windows 10, python 3.7 and pyinstaller version 3.5.
I wrote some script in pycharm and when i hit run (from the pycharm IDE) its work fine.
but when I execute it by pyinstaller to exe ("pyinstaller --onefile design.py"),
I click the file inside the dist folder (design.exe) and i get this error
Traceback (most recent call last):
File "design21.py", line 10, in <module>
ModuleNotFoundError: No module named 'PyQt5'
[11116] Failed to execute script design21
my code start with:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'gui_with_layouts.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QThread,pyqtSignal
from style import *
from firebase import firebase
import xlrd
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time
from PyQt5.QtWidgets import *
stop_flag = False
UPDATE:
I dont know how but i did the next step and somehow it work:
delete line 10 and 11 (that import the 'Pyqt5')
execute new exe (from cmd the commend pyinstaller --onefile design21.py)
run the new exe file from the dist folder (Of course I got errors, because I used the moudle 'Pyqt5' without importing it).
4.add again the import line (that lines that i deleted 10 and 11).
execute again new exe (from cmd the commend pyinstaller --onefile design21.py)
then when I run the new exe it work...
no idea why but its worked.
you need to install pyqt5.
just open CMD and install it.
pip install pyqt5
No module named 'PyQt5' here not PyQt5 not installed on python environment install correctly or use the right python environment.
Pycharm editor goto project setting and choose python environment with 'PyQt5'
OR pycharm bottom CMD install a pip install PyQt5
I just ran into the same problem. For me importing sip in the first line of the programm solved the issue:
from PyQt5 import sip

No module named 'PyQt5.QtWebEngineWidgets' Error

I have instlled PyQtWebEngine module with pip but I get this python error:
No module named 'PyQt5.QtWebEngineWidgets'
my code is :
import sys
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
web = QWebEngineView()
web.load(QUrl(r'C:\Users\Hss\Desktop\hi.html'))
web.show()
sys.exit(app.exec_())
how i solve this problem?(All library is updated)
try the repair option on your python installer or try reinstalling python or the IDE

Python 3.7 Anaconda: "ImportError: cannot import name 'QtWebKitWidgets' from 'PyQt5'" [duplicate]

I've recently upgraded PyQt5 from 5.5.1 to 5.6.0 using the Windows 32-bit installer here: https://www.riverbankcomputing.com/software/pyqt/download5. I've also upgraded my python from 3.4 to 3.5.
When I run my old code (which used to work) with the latest version I get an exception:
from PyQt5.QtWebKitWidgets import *
ImportError: No module named 'PyQt5.QtWebKitWidgets'
All of my QT calls in my python occur consecutively and are (and I know I shouldn't be importing * but that's beside the issue here I think):
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebKitWidgets import *
So the QtCore, QtGui and QtWidgets imports are all OK.
Also, when I search the source for QtWebKitWidgets there appears several references to this module.
Finally my python path looks like:
C:\PYTHON35;C:\PYTHON35\DLLs;C:\PYTHON35\LIB;C:\PYTHON35\LIB\LIB-TK;
and environment path:
C:\Python35\Lib\site-packages\PyQt5;C:\Python35;C:\Python35\Lib;C:\Python35\Lib\site-packages;C:\Python35\Scripts ....
QtWebKit got deprecated upstream in Qt 5.5 and removed in 5.6.
You may want to switch to PyQt5.QtWebEngineWidgets.QWebEngineView.
For basic use of PyQt5.QtWebKitWidgets.QWebView, it can simply be updated to use PyQt5.QtWebEngineWidgets.QWebEngineView in the source code, but there may be some differences in the new component which require further adjustments.
I was trying to run qutebrowser and it had the same error, the answer is simple, the packages changed.
You have two solutions:
1)
pip install PyQtWebEngine
2)
pip install PyQt5==5.11.3
Hope this helps any future problems
In PyQt5 "QtWebKitWidgets" is Deprecated. I just replace this line
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from PyQt5.QtWebKit import QWebSettings
With this code:
from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView,QWebEnginePage as QWebPage
from PyQt5.QtWebEngineWidgets import QWebEngineSettings as QWebSettings
If you really want to use PyQt5.QtWebKitWidgets, you could run this from the command line:
pip install PyQtWebKit
and let it do what it does.
In PyQt5 "QtWebKitWidgets" is no longer available. Instead it is replaced with "QtWebEngineWidgets". So you have to make this change in your code.
For more information: http://doc.qt.io/qt-5/qtwebenginewidgets-qtwebkitportingguide.html

Python 3.4/PyQt5 Cannot import QtCore

I'm trying to run an example script using PyQt 5 that contains the following:
import sys
from PyQt5 import QtCore, QtGui, uic
This throws:
ImportError: cannot import name 'QtCore'
I'm running 64-bit versions of both Python 3.4 and PyQt 5 on 64-bit Windows 10. When I try
from PyQt5 import QtCore
in the terminal it works fine; I only get the import error when running a script. Other similar questions on StackOverflow led me to check sys.path, which produced:
>>> print(sys.path)
['', 'C:\\Windows\\SYSTEM32\\python34.zip', 'C:\\Python34\\DLLs',
'C:\\Python34\\lib', 'C:\\Python34', 'C:\\Python34\\lib\\site-packages',
'C:\\Python34\\lib\\site-packages\\PyQt5']
os.environ['PATH'].split(os.pathsep)
results in a long list of directories, including the location of PyQt5 in the Python34 folder.
I've also tried uninstalling and reinstalling both Python and PyQt, and tried PyQt4 instead of 5, all with no success.

Categories