Cannot import PyQtChart in Python 3.7 - python

I am able to install PyQtChart without error using pip, but I cannot import it as Python (3.7.3) tells me there is no such module.
I'm using Anaconda's Python distribution on Windows 10, but its version of PyQt5 is really old. After seeing a question with a comment by eyllanesc I uninstalled PyQt5 from Anaconda and reinstalled (the current 5.13 version) via pip. Everything with that worked fine and my PyQt5 is the latest version and imports and works well. But PyQtChart isn't importing. I installed like this:
OK> pip install --user PyQtChart
Collecting PyQtChart
Downloading https://files.pythonhosted.org/packages/a2/4c/2bf0482300e6ae407d33fcc098c310de00a86f3ee0755ae5419298e5e5c3/PyQtChart-5.13.0-5.13.1-cp35.cp36.cp37.cp38-none-win_amd64.whl (848kB)
|████████████████████████████████| 849kB 6.4MB/s
Requirement already satisfied: PyQt5>=5.13 in d:\programdata\anaconda3\lib\site-packages (from PyQtChart) (5.13.1)
Requirement already satisfied: PyQt5_sip<13,>=4.19.19 in d:\programdata\anaconda3\lib\site-packages (from PyQt5>=5.13->PyQtChart) (4.19.19)
Installing collected packages: PyQtChart
Successfully installed PyQtChart-5.13.0
OK> pip list
Package Version
---------------------- ---------
...
PyQt5 5.13.1
PyQt5-sip 4.19.19
PyQtChart 5.13.0
and when I import I get the error:
ModuleNotFoundError: No module named 'PyQtChart'
I also looked through the dir(PyQt5) and there is no submodule or component for charts.
How can get this to import properly?
EDIT:
As I mentioned, I already looked for other modules. This code is not helpful, but requested.
import PyQt5
import PyQtChart as qtch
#from PyQt5 import QtChart
d = dir(PyQt5)
for i in d:
if "chart" in i.lower():
print(i)
I TRIED multiple ways to install and import, including the suggested ways. Pip3 would not install the module.

You have to have the same version of PyQt5 and PyQtChart installed:
python -m pip install PyQt5==5.13 PyQtChart==5.13
TL; DR;
PyQt is a wrapper of the Qt, and each version of Qt generates .dll/.so that are not compatible with other versions. So that same problem moves to PyQt. In your case it is observed that the PyQt5 and PyQtChart libraries use different versions of Qt generating incompatibility.
On the other hand that a module is called X does not imply that it is imported using: import X, in the case of PyQtChart you should use: from PyQt5 import QtChart.

For me: only "pip install PyQtChart" this update PYQT5 and install module PyQt5.QtChart

Related

ImportError: No module named xgboost and package already installed

When I do:
import xgboost
I get no module named xgboost
I tried:
pip install xgboost
and i get:
Requirement already satisfied: xgboost in e:\anaconda\lib\site-packages (1.0.2)
Requirement already satisfied: numpy in e:\anaconda\lib\site-packages (from xgboost) (1.18.1)
Requirement already satisfied: scipy in e:\anaconda\lib\site-packages (from xgboost) (1.4.1)
versions
Python 3.7.4
pip 20.0.2 from E:\Anaconda\lib\site-packages\pip (python 3.7)
Where python:
E:\Anaconda\python.exe
C:\Users\Federico\AppData\Local\Microsoft\WindowsApps\python.exe
Usually this will happen because
You installed the package in a virtualenv and are trying to import it outside of the env
You installed the package globally and are trying to import it in a virtualenv which does not inherit the global packages
Your pip is linked to a different version than the python you're using
Based on the output of the where python it seems like you probably used the pip from anaconda to install the package, but are trying to import the package in a script that you're running with the python located here C:\Users\Federico\AppData\Local\Microsoft\WindowsApps\python.exe rather than here E:\Anaconda\python.exe
If your code with the import is in a script called test.py, for example, try running it with E:\Anaconda\python.exe test.py and see if the error still occurs
Or start a Python shell with E:\Anaconda\python.exe and then execute import xgboost in the shell and see if that works

No module named PyQt5.sip

After upgrading to python-pyqt5 5.12-2 I get this error when I try to import from QtWidgets
from PyQt5.QtWidgets import *
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.sip'
Any idea on how can I solve this issue?
The reason is a backward incompatible change in PyQt-5.11
In geoptics this fix works on old and new versions:
try:
# new location for sip
# https://www.riverbankcomputing.com/static/Docs/PyQt5/incompatibilities.html#pyqt-v5-11
from PyQt5 import sip
except ImportError:
import sip
As suggested here pyuic5 - ModuleNotFoundError: No module named PyQt5.sip
Try uninstalling and re-installing all PyQt related libraries:
pip uninstall PyQt5
pip uninstall PyQt5-sip
pip uninstall PyQtWebEngine
Then install them again, this will fix:
ModuleNotFoundError: No module named 'PyQt5.sip'
ModuleNotFoundError: No module named 'PyQt5.QtWebEngineWidgets'
PPS.:If you got problems uninstalling the libraries, go to your Python folder, like C:\Users\<USERNAME>\AppData\Local\Programs\Python\Python<PYTHON-VERSION>\Lib\site-packages and manually delete the PyQt folders, them uninstall everything and install again (Make sure you have the latest Python version and upgraded your pip too)
If you're building sip and PyQt5 from source using make files, make sure to check PyQt5 install docs. In particular,
Note
When building PyQt5 v5.11 or later you must configure SIP to create a
private copy of the sip module using a command line similar to the
following:
python configure.py --sip-module PyQt5.sip
If you already have SIP installed and you just want to build and
install the private copy of the module then add the --no-tools option.
You should add PyQt5.sip to hidden imports; that should solve the issue.
I repaired this problem
This problem occurred when upgrading pyqt5 version 5.15.0
There was no problem when I reverted to the previous version.
I have
python -V: 3.7.4
PYQT5 5.14.1 and PYSIDE 5.14.1 works fine
In addition to the answer provided by Tadeu (https://stackoverflow.com/a/58880976/12455023) I would also suggest checking version of your libraries to make sure that they match.
Use pip show <library_name>
This will help you to make sure that no earlier installation is conflicting with your current installation.
In place of library_name use PyQt5, PyQt5-sip, PyQtWebEngine. If any of them is present in the system, then use pip uninstall <library_name>==<version_number> to remove that library.
Once you made sure that no other versions of these libraries are there, then you can reinstall the preferred version of that library.

ModuleNotFoundError: No module named 'spatial'

I've been faced to Module Not Found Error in a script which all it's requirements has been installed. I'm trying to import spatial library:
import spatial
This library is located here:
C:\Users\ASUS\AppData\Local\Programs\Python\Python37\Lib\site-packages\scipy\spatial
I checked installed packages through pip list and it was okay. I tried to install spatial-lib in Pycharm project environment but it couldn't be done:
Could not find a version that satisfies the requirement spatial-lib (from versions: )
No matching distribution found for spatial-lib
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
It's nonesence, because my pip is up-to-date. Maybe good to say, importing scipy has such probelms too.
It looks like spatial is a sub-package of scipy. Therefore, to import spatial, you should use the following:
from scipy import spatial

No module name _tkinter error while tkinter is installed

When trying to run my python 3 program that uses matplotlib via the command line, I get the following error:
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
The same happens when simply inputting:
>>>import tkinter
Suggested fixes such as installing python3-tk, python3.5-tk or python3.6-tk do not work, the result is:
python3.6-tk is already the newest version (3.6.6-1+xenial1).
and using matplotlib.use('agg') does not work as I need to output figures:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
with pip install tkinter, python-tk or python3-tk the result is :
Could not find a version that satisfies the requirement python3-tk (from versions: )
No matching distribution found for python3-tk
I also tried updating and reinstalling python3 but nothing seems to work (version 3.6.4). Could it be that python-tk is version 3.6.6 and my python 3.6.4?
Is there any other method I can try?

How to install PyQt5 in PyCharm?

When I try to import the following using PyCharm:
import sys
from PyQt5.QtWidgets import QtGui, QtCore
it generates this error when compiling:
ImportError: No module named 'PyQt5'
I want PyQt5 in Pycharm. Can you explain in complete detail what should I do to install it?
Try
PyCharm -> file -> settings -> project:'your_project' - project interpreter -> + -> install PyQt5
pip install PyQt5 doesn't work for PyCharm
Install PyQt5 from the installer on the PyQt website. It probably just installs PyQt as a site package to the python version you point to in your 'Path', although it may ask for your preference - cant remember.
It also installs other useful PyQt stuff to your hard drive.
It also updates the path to the PyQt module so you can easily run the pyuic5.bat file from the command line to convert the .ui generated by 'Qt Designer' to a python file.
No configuration of PyCharm should be necessary and it will pick up any new site packages added automatically.
also...
from PyQt5 import QtCore, QtGui, QtWidgets
The reason why you cannot pip install PyQt5 is because the Python Package Index (PyPi -- where pip searches for packages) was not provided with the files to serve.
Put another way: when you use pip search, you are being provided with a list of projects that have been registered with PyPi, whether or not downloadable source files were made available.
Contrast the PyPi page for easyos, where a download of the files has been made available, to PyQt5, where they have not been.
To install PyQt5, follow the "Download URL" on the PyPi page and install it according to the provider's instructions. You may have to repeat this process for additional packages and should make note of steps taken in case you have to repeat them in the future -- steps taken outside of pip do not make it into your requirements.txt.
Note PyQt5 pip packaging requires Python 3.5 or later. With PyCharm 2017 you can install from the ide write the ´import PyQt5´ in your code, press alt enter on the missing import and select "import PyQt5".
Or from the command line as per the latest installation instructions:
pip3 install pyqt5
For Linux OS users(Ubuntu and Debian base distributions):
For installing PyQt4:
sudo apt install pyqt4-dev-tools
For installing PyQt5:
sudo apt install pyqt5-dev-tools
In General, GNU/Linux users can install pyqt5 it using the below command:
pip3 install pyqt5
The installation instructions are fully described here.
Open terminal from PyCharm (View -> Tools Windows -> Terminal) and type the following:
python -m pip install pyqt5

Categories