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.
Related
My Python import could not be found after i changed the directory and restarted VSCode.
I installed the package via cmd (pip install ) and it was found in Vscode.
I restarted VSCode because i changed the file location to a other directory. The package wasnt found since then. I uninstalled the package and installed it via Powershell but it wouldnt work. Updated the pip installer.
Created a new file with in the directory where it has been before and installed the package again.
VSCode doesnt recognize the package anymore.
Import "" could not be Resolved (Pylance(reportMissingImports))
Does anybody know why this behavious appears and how to fix it?
I havent found a proper solution on here or another forum
In the bottom right of your VS code instance, you'll see something like 3.11.0 64-bit, which indicates the version of Python that VS code is referring to when running and linting your code. The problem is you installed the package with a different version of Python. If you click on the aforementioned button (that says 3.11.0 64-bit) you should see a list of options show up for the different Python versions installed. You need to change to the one that you installed the package on.
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.
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.
I had PyQt4 running fine with python2 on Ubuntu 12.04. I then installed python-PySide. But the installation test would give me a module not found error. Then I installed python3-PySide and it works fine. So obviously something to do with my environment paths, but I'm not sure what I need to do. I'm guessing PySide is automatically checking if python3 exists and if it does then it'll use it regardless. I need PySide to work with python2.7 because of Qt4.8 compatibility issues. Any suggestions?
some info about my system:
which python
/usr/bin/local/python
which python3
/usr/bin/python3
EDIT:
More details about installation test.
After installation, I bring up the python console and try import PySide, as follows:
python
import PySide
ImportError: No module name PySide
But it works fine for python3:
python3
import PySide
PySide.version
'1.1.2'
You have two independent Python 2.7 installations, one in /usr and one in /usr/local. (And that's on top of the Python 3.x installation you also have.)
This is bound to cause confusion, especially for novices. And it has caused exactly the kind of consuion it was bound to cause.
You've installed PySide into the /usr installation, so it ended up in /usr/lib/python2.7/dist-packages. If you run /usr/bin/python, that import PySide will probably work fine. (If not, see below.)
But the default thing called python and python2.7 on your PATH is the /usr/local installation, hence which python says /usr/local/bin/python, so it can't see PySide at all. So you need to get it installed for the other Python as well.
Unless you know that you need a second Python 2.7 in /usr/local for some reason, the simplest thing to do would be to scrap it. Don't uninstall it and reinstall it; just uninstall it. You've already got a Python 2.7 in /usr, and you don't need two of them.
If you really need to get PySide working with the second 2.7…
Since you still haven't explained how you've been installing PySide despite being asked repeatedly, I can't tell you exactly how to do that. But generally, the key is to make sure to use explicit paths for all Python programs (python itself, python-config, pip, easy_install, etc.) that you have to run. For example, if the docs or blog or voices in your head tell you to run easy_install at some step, run /usr/local/bin/easy_install instead. If there is no such program, then you need to install that. The fact that you already have /usr/bin/easy_install doesn't help—in fact, it hurts.
If you can get rid of the second Python, but that doesn't fix PySide yet, uninstall, rebuild, and reinstall PySide. Or, even simpler… PySide has pre-made, working binary Ubuntu packages for all of the major Python versions that have Ubuntu packages. Just install it that way.
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