pyqt is installed but it won't import (Mac) - python

I installed PyQt4 and I have xcode, Qt, Sip, and Python 2.7. When I check in terminal, it says that PyQt is installed and when I view the path there is no PyQt in the path. I have put it in the path before but it goes away when I close the shell. When I try and import it it says no module named PyQt4. Help
brew install pyqt
Warning: pyqt-4.11.4 already installed
>>> for f in sys.path:
print f
/Users/lucygrant/Documents
/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
/Library/Python/2.7/site-packages
>>> import PyQt4
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import PyQt4
ImportError: No module named PyQt4

Assuming that adding PyQt4 to PATH solved your problem before, do it again except now do it in the ~/.bashrc file. So, as follows:
Add PyQt4 to PATH in ~/.bashrc as you have previously done.
source ~/.bashrc from command line.
Reattempt import

Related

PyQt5.QtWidgets module not found when pyqt is installed with Anaconda

I can import PyQt5 but I cannot import from PyQt5.QtWidgets when I install pyqt in a conda environment.
I've tried uninstalling and reinstalling with conda and that did not solve the problem.
If I install with pip in a regular virtual environment instead of with Anaconda then it works.
This is the code:
from PyQt5.QtWidgets import *
This is the error:
$ python main.py
Traceback (most recent call last):
File "main.py", line 1, in <module>
from PyQt5.QtWidgets import *
ModuleNotFoundError: No module named 'PyQt5.QtWidgets'
Turns out it was a path problem. I had installed Homebrew after Anaconda and /usr/local/bin was in front of $HOME/anaconda3/bin in $PATH, so Homebrew Python was being called instead of Anaconda Python.

pyuic4 ImportError: No module named port_v2.ascii_upper

I'm trying to convert a Qt widget created with Qt Designer in a py file using ' pyuic4
I just do
pyuic4 widget.ui -o ui_widget.py
But I get this error:
Traceback (most recent call last):
File "/usr/bin/pyuic4", line 3, in <module>
import PyQt4.uic.pyuic
File "/usr/lib/python3/dist-packages/PyQt4/uic/__init__.py", line 43, in <module>
from PyQt4.uic.Compiler import indenter, compiler
File "/usr/lib/python3/dist-packages/PyQt4/uic/Compiler/compiler.py", line 43, in <module>
from PyQt4.uic.properties import Properties
File "/usr/lib/python3/dist-packages/PyQt4/uic/properties.py", line 51, in <module>
from PyQt4.uic.port_v2.ascii_upper import ascii_upper
ImportError: No module named port_v2.ascii_upper
I have been researching the involved modules and I can see this lines in properties.py and pyuic.py
if sys.hexversion >= 0x03000000:
from PyQt4.uic.port_v3.ascii_upper import ascii_upper
else:
from PyQt4.uic.port_v2.ascii_upper import ascii_upper
(I can see in Riverbank's page that there are a branch with v2 ascii, but I haven't installed)
If I do in command line:
python (v2.7.12)
>>> import sys
>>> print hex(sys.hexversion)
0x2070cf0
>>>
Then I do the same in python3 (3.5.2)
>>> import sys
>>> print (hex(sys.hexversion))
0x30502f0
>>>
Well...looks as if pyuic4 calls a python 2 version. But I don't know what I need for execute pyuic4 with python3
Another data related with PyQt4 (I don't know if it's useful):
>>> import PyQt4
>>> from PyQt4 import QtCore
>>> print ((QtCore.PYQT_VERSION_STR, QtCore.QT_VERSION_STR))
('4.11.4', '4.8.7')
>>>
Edit:
This is installed from pyqt4-dev-tools package (linux mint).
If I try to install using PIP I get this error:
pip3 install pyuic4
Collecting pyuic4
Could not find a version that
satisfies the requirement pyuic4 (from versions: ) No matching
distribution found for pyuic4 You are using pip version 8.1.1, however
version 19.0.3 is available. You should consider upgrading via the
'pip install --upgrade pip' command.
Edit2 and posible solution
Thanks to #ekhumoro I've got solved my problem. This is the content of /usr/bin/pyuic4
#! /usr/bin/python
# there's no main function, so just import the module
import PyQt4.uic.pyuic
I need to point to python3, so I've just modify the first line:
#! /usr/bin/python3
Thanks a lot!

Can't start spyder because of PyQt5.QtWebKitWidgets

I have a problem with spyder.
I just installed on this laptop Python 3.7 and Spyder, as I did on many others. However this time, it doesn't work.
I installed Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32 with the installer. I changed the path to a custom path: C:\Python\Python37, I added the precompile library and I added the path to the environment.
The laptop was rebooted at that point.
Then I updated pip:
py -3.7 -m pip install --upgrade pip
And then I installed spyder:
py -3.7 -m pip install spyder
I then try to launch spyder with the file:
C:\Python\Pythno37\Lib\site-packages\spyder\app\start.py
I get the error:
ModuleNotFoundError: No module named 'PyQt5.QtWebKitWidgets'
PyQt5 is installed with version 5.12.
No clue why it doesn't work...
EDIT: The full error message:
It sugggest that the problem comes from qtpy. However, the corresponding file imports:
from . import PYQT5,PYSIDE2, PYQT4, PYSIDE, PythonQtError
# To test if we are using WebEngine or WebKit
WEBENGINE = True
if PYQT5:
try:
from PyQt5.QtWebEngineWidgets import QWebEnginePage
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWebEngineWidgets import QWebEngineSettings
except ImportError:
from PyQt5.QtWebKitWidgets import QWebPage as QWebEnginePage
from PyQt5.QtWebKitWidgets import QWebView as QWebEngineView
from PyQt5.QtWebKit import QWebSettings as QWebEngineSettings
WEBENGINE = False
The PyQt5.QtWebEngnieWidgets is correctly used.
I swapped Pyqt5 version from 5.12 to 5.11.2 with:
py -m pip install pyqt5==5.11.2
And now it works...
Three days ago I was playing around with Python, Mayavi and Jupyter Notebooks to create visualizations. This required to install PyQt5.
Due to constantly reaching memory errors, I've decided to test without using virtualenv's and installed the needed requirements on my local environment (which of course didn't solve).
After that, I was on my way to create visualizations using matplotlib and other Python libraries but can't launch Spyder from the Anaconda Navigator.
This is the error showing up, which is similar to yours
Traceback (most recent call last):
File "C:\Users\tiago\Anaconda3\lib\site-packages\qtpy\QtWebEngineWidgets.py", line 22, in
from PyQt5.QtWebEngineWidgets import QWebEnginePage
ModuleNotFoundError: No module named 'PyQt5.QtWebEngineWidgets'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\tiago\Anaconda3\Scripts\spyder-script.py", line 10, in
sys.exit(main())
File "C:\Users\tiago\Anaconda3\lib\site-packages\spyder\app\start.py", line 186, in main
from spyder.app import mainwindow
File "C:\Users\tiago\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 90, in
from qtpy import QtWebEngineWidgets # analysis:ignore
File "C:\Users\tiago\Anaconda3\lib\site-packages\qtpy\QtWebEngineWidgets.py", line 26, in
from PyQt5.QtWebKitWidgets import QWebPage as QWebEnginePage
ModuleNotFoundError: No module named 'PyQt5.QtWebKitWidgets'
The correct answer didn't work in my case.
This problem had to do with the PyQt5 installation. The way to fix it was to uninstall it
pip uninstall PyQt5
and then Spyder launched perfectly

ImportError: No module named 'gammu'

I work on Ubuntu Xenial (16.04) with python3, I also installed anaconda.
I installed python3-gammu (with apt install python3-gammu or/and pip install python3-gammu) to test send SMS.
Just run python3 console and
>>> import gammu
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'gammu'
import sys
print(sys.path)
only return anaconda paths !
If I run
sudo find -iname gammu
…
./usr/lib/python3/dist-packages/gam
…
so if I add this path:
>>> sys.path.append('/usr/lib/python3/dist-packages/')
>>> import gammu
and it works !
Could you clarify this library path issue?
just
export PYTHONPATH=$PYTHONPATH:/usr/lib/python3/dist-packages/
To keep it at next reboot, put this line in your ~/.bashrc :
# added by Anaconda3 4.2.0 installer
export PATH="/home/my_user_name/anaconda3/bin:$PATH"
export PYTHONPATH="/usr/lib/python3/dist-packages/:$PYTHONPATH"
to active new .bashrc, do not forget to run
source ~/.bashrc
When you are trying to import any package it will check sys.path, which contains all paths of packages. If it find the package you want to import it will import it.
sorry for bad english...
Why use sys.path.append(path) instead of sys.path.insert(1, path)?
You may get clarity after seeing this ?

virtualenv's python can't find PyQt4

Running OSX (10.8.2) here, replaced their python with Homebrew's. All good:
$ which python
/usr/local/bin/python
Installed pip, virtualenv with brew python. Installed pyqt with brew.
If I
$ python
>>> import PyQt4
, no problems. However, if I
(env)$ python
>>> import PyQt4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4
Why can't the virtualenv python environment see my system-wide install of pyqt?
Thanks!

Categories