pyqtgraph is installed but isn't recognized when I import it - python

I am trying to run this code that visualizes audio waveforms and their fourier transforms
https://github.com/markjay4k/Audio-Spectrum-Analyzer-in-Python/commit/ff9caf4156b7a8c039d8beba987f93566a6aace0
It requires numpy, PyQt, and pyqtgraph. When I run it, I get an error right of the bat.
from pyqtgraph.Qt import QtGui, QtCore
ModuleNotFoundError: No module named 'pyqtgraph'
I know I installed this, because I have pyqtgraph in my site-packages folder. I used pip install pyqtgraph to install it, and if I run the command again, it confirms that the install has already been performed.
What am I doing wrong? Is there some version incompatability? Do I need to do a little dance in my PJs to get it working? I'm not sure.

This normally happens when you try to use a library in either a different Python version, virtual environment, or platform. I'd troubleshoot as follows:
Check for typos and that you are using the correct way to import the library and submodules.
If you have multiple Python versions, make sure you are running on the one where the library is installed.
If you use both pip and conda, make sure you are running the code on the correct platform.
If both the Python version and platform are ok, check you are working in the same virtual environment where you installed the library in question. I think this is the most probable cause.
You can find plenty of tutorials on how to check all the above. If nothing works, you can try uninstalling and reinstalling.

Related

PyCharm finds library but not module

I am using PyQt5 in PyCharm Community Edition. I have installed qt5-serialport as described in this question and when I use python on the command line I am able to do from PyQt5.QtSerialPort import QSerialPort and use the QSerialPort module with no problem in the interactive python environment and when running a python script that makes use of the QSerialPort module, so it's clear that python itself is finding the module just fine. However in PyCharm, the module is not found despite the fact that I'm using the system python as the interpreter. On the line from PyQt5.QtSerialPort import QSerialPort PyCharm underlines QSerialPort in red and it doesn't offer any tooltip suggestions for methods etc. on any QSerialPort object I instantiate.
Normally when I get this kind of problem I install the package using the installer within PyCharm but this particular package doesn't seem to be in any public repo listing I can find. (Somehow yay found it, despite it not being listed in the searchable AUR). Other modules in the PyQt5 package import in PyCharm without problems. How can I get PyCharm Community Edition to recognize this module?
Installing it on the terminal should work using pip from python.org.
pip install PyQt5
This approach appears to work since it has the core features for finding, downloading, and installing packages from various Python package indexes. More info on pip from python.org.
According to the Troubleshooting tips from JetBrains listed for PyCharm, there is useful info on debugging import errors using PyQt. So this may be the cause as to why installation through the IDE was not working even though PyQt was installed on the interpreter.

PyCharm error - No module named 'sip' (PyQt4)

OK, so I need to make a project in PyQt, and I'm using PyQt4 since I found more tutorials on this and it is easier for me.
I installed PyCharm as my IDE. I haven't had any python compilers so I installed Python 3.7.5 (from Microsoft Store since PyCharm recommended that), and configured the interpreter in PyCharm (so now, python works)
Then, I needed to install PyQt4, and since it didn't work from PyCharm's project interpreter -> install package, I downloaded "PyQt4-4.11.4-cp37-cp37m-win_amd64" and installed it with pip.
Then, I installed sip also with pip.
The thing is that I get an error in my code in PyCharm.
from PyQt4 import QtGui
ModuleNotFoundError: No module named 'sip'
I also configured all my Windows PATHs, when I installed sip it gave me an error saying that the path isn't added. I added that path.
I also added the pyqt4 path.
These are my paths:
C:\Users\b997a\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\sipbuild
C:\Users\b997a\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages
'C:\Users\b997a\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts
And these are all the packages I think I have installed in PyCharm:
Do you know what I can do? I really don't want to use PyQt5 since I know a found tutorials on exactly what I want to do on PyQt4 and I don't really have time to learn PyQt5 now...
I also tried to see if Python 3.7.5 Shell (IDLE) will raise an error, and yes, it did. I have the same error in Python's IDLE.
What is the problem? It worked for a while until I deleted Python a few weeks ago, but now it doesn't work anymore.
Thanks a lot!
I have recently faced such issues, so my recommendations are:
It's good to activate your virtual env for your project.
Usually pip should install the required binaries, but if it doesn't, try searching the same from pycharm -> settings and add directly from there. This has always worked for me.
P.S. I was not able to add comment, so I posted it as answer.

How to import python packages without pip install

The server that I am using has an older version of python installed, and I am unable to install packages. Is there a workaround to importing python modules? If I can create my own module and append the directory to be able to import the newly created module, then I am assuming that I should be able to do the same for already built packages. I just need to know how I would be able to install what is required for numpy and then import it using a similar method as when creating modules.
I would recommend that you find a machine to install the same version of Python to match your server. Perform the pip install from that stand alone machine. Do some level of testing to make sure that the code with run with that version of Python and everything is happy. Just the other day I found out the hard way that TensorFlow would now work on the latest Python.
The libraries are being installed for me under c:\users\<profilename>\AppData\Local\Programs\Python\Python36\Lib\site-packages So you could then copy that over to the server.
I found this link that is saying the same thing.
https://superuser.com/questions/943980/is-it-possible-to-install-python-packages-without-a-direct-outbound-network-conn
Good Luck with it.

How can I run matplotlib in Pycharm on macOS?

I can run code through terminal and have a matplotlib window pop up with the graph but not through Pycharm. All I get is an error saying:
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
I'm not sure how to install Python as a framework or what that really means. I've googled about but I don't want to mess my system up.
Can someone offer a solution at least of what I should be trying to do or what to google around for.
Sorry if I lack some of the technical language/knowledge to explain this problem. Thanks
macOS High Sierra 10.13.1
If you install matplotlib with pip, or conda, you should have a directory ~/.matplotlib.
Inside that directory create, or open if it already exists, a file called matplotlibrc.
To make TkAgg the default backend just add the line backend: TkAgg
I found a short term fix until I can make changes to the necessary files from user Iron Pillow.
import matplotlib
matplotlib.use('TkAgg')
I just insert this before I import any matplotlib subpackages.
I encountered a similar situation that a graph report library based on matplotlib works fine on Conda, Jupyter, but not in Pycharm. It can generate a multi-page pdf. But when I run a program that calls the report library inside Pycharm on MacOS, and the pdf can not be generated properly.
My python 3.6 installation is from Anaconda. I found two solutions. First solution is to run pythonw from a terminal. This is obviously outside of Pycharm, and is not as convenient as you wish.
The second solution is to add "backend: TkAgg" to matplotlibrc.
This file can exist in several places. If this change is meant to be personal, then this file can live under ~/.matplotlib. You can even add this file in the current working directory, to make it part of the program you run.
This is the least intrusive solution without having to add python code that breaks platform compatibility. Formal documentation can be found in the "The matplotlibrc file" section of https://matplotlib.org/users/customizing.html
You just have to install python. You can do that using Homebrew.
In a terminal run:
sudo brew install python

Pycharm, PyQt5, and Python 2.7 -- No code completion

I've got:
Python 2.7 (Anaconda x64), which works great
PyQt5 (installed using pip install python-qt5)
PyCharm 4.04 Professional (recently upgraded from 3.4.1)
A small Qt application
After much hair-pulling (since Riverbank doesn't provide a PyQt5 binary for Python 2.7, only for 3.3+) I got everything working thanks to Marcus Otosson's pre-compiled binary packages.
Qt is now installed and fully functional. My Qt application runs great!
But the application isn't finished yet, and PyCharm won't do code completion for the PyQt modules. It won't even recognize that any PyQt5 sub-modules (like Qwidgets) exist: even though they work just fine, I still get the red squiggly "Unresolved Reference" warning.
How do I fix this? I assume this has to do with the inherent difficulties in generating skeletons for binary *.pyd files. How does it work exactly? Can I manually generate code skeletons, or import them from somewhere they generated correctly?
Uninstalling and re-installing PyCharm didn't help. Neither did re-configuring the interpreter to force the skeleton generator to run again.
Please help before I go bald.
Can you find PyQt5 from your project's External Libraries?
If you install it through pip, you should be able to see the library directly. Once the library can be referred, it will do the code-completion for you.
I am using PyCharm4(community Edititon) on Windows with PyQt4, the autocomplete is fine. As PyQt4 is actually a dynamic library to be dynamic loaded by the python interpreter ( you can look into the PyQt4 folder, there is no python files there except some init.py), auto-complete depends on the source code of PyQt4 itself, so when using pycharm, it usually generally some local python cache for complete. For my machine, a typically file looks like:
C:\Users\cui.PyCharm40\system\python_stubs-762174762\PyQt4\QtCore\QString.py
You can also try install PyQt document from Pycharm.
File->settings->Tools->python external document->PyQt
Had the same problem in PyCharm 2017.1.1. Don't do
import PyQt5.QtWidgets
do
from PyQt5 import QtWidgets

Categories