On my office PC I'm using
Python 3.4
PyQt4 Version 4.11.1
PyCharm Community Eddition 3.4.1
I installed everything in the order as stated above.
However, code completion does not work. It works for imports, but not for classes and methods.
I made a small sample program:
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
window = QtGui.QWidget()
window.setWindowTitle("Test")
window.resize(300, 200)
window.show()
sys.exit(app.exec_())
In the code above none of the classes or methods were suggested by PyCharm.
If I type window.setW I would expect it to suggest setWindowTitle() but it doesn't.
Strange thing is, that I'm using the same setup on my computer at home and there it works like a (Py)charm... Autocompletion, auto imports, etc. As far as I remember I installed it the same way as I did on my office PC.
I already looked at some similiar questions but this question has no answers and others don't contain relevant information that helped me so far.
Don't know if it is relevant but at this line
from PyQt4 import QtGui
PyCharm tells me
Unresolved reference 'QtGui'
Maybe the reason for this is the same.
I had the same problem on Linux, pyqt5 and pycharm CE.
The solution was to rebuild the skeletons with:
File > Invalidate Caches / Restart > Invalidate and Restart.
The problem was solved by installing PyCharm first and then Python and PyQt.
Afterwards I had to configure the interpreter in PyCharm and it worked.
When I posted the question I installed Python, then PyQt and then PyCharm.
Oddly enough, it worked in this order on another PC.
I went through the same issue recently. Unfortunately, the install order didn't solve it for me.
There is a bug report here. Downloading the Early Access Program release worked and can be found here
Related
I use vscode as my python IDE, and had installed some nessary plugins such as python and pylance for it. But now I have a problem, the pylance for vscode could not reconizge the PySide6 modules for quick fix auto import, like following picture shows:
But the quick fix work for other modules.
Could someone help to point out how to resolve it? It worked before but one day could not work any more.
Sorry, but normally, we will not act like this. We will not type a complex or long className then import it through a quick fix. at most we type sys and import it immediately.
I'm learning Tkinter right now and trying to work through my first issue, but finding Google hasn't been helpful.
I'm running this code on Mac OS X 10.15.1 (Catalina)
I'm using Python 3.7 and my code looks like so (lots of boilerplate per PEP8 standards):
"""
Experiments in tkinter
"""
import tkinter as tk
def main():
"""
Main entrypoint
"""
tk._test()
if __name__ == "__main__":
main()
This outputs the following warning to the console:
DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.
It also displays a window with completely blank buttons:
From my understanding these buttons should say "Click Me" and "Quit".
Also when I click on the top button it flashes black for a second like so:
After which the button is wider than before:
I assume the Tk version error may be related to the output behavior. However I can't seem to find a way to update Tk. What should I do here?
Update
After seeing #ShayneLoyd's answer (suggesting I needed an updated version of Python with an updated version of Tk) I began looking around some more and found this post on the Apple Discussion Boards which suggests you can use homebrew to install a version of Python which link's homebrew's own installed version of Tk. I tried this and it failed, so I Google'd the issue and found this StackOverflow post which seemed to suggest I can install
ActiveTcl and it will work.
I installed ActiveTcl from ActiveState and went back to my project. At first, I ran it like so:
$> cd ~/Source/experiments/python/tkinter
$> ./test.py
This actually worked! I could read the buttons and it behaved like it should. Then I realized I was not using pipenv, so I did a quick test:
$> pipenv run ./test.py
Now I was back to the failure state. I updated my script to display the Tcl and Tk version and sure enough when I used pipenv it was loading Tcl/Tk 8.5.9 but when I didn't use pipenv it was loading 8.6.9
So how do I fix pipenv now?
For anyone who's having the same issue and cannot switch Python version, you can easily bypass the "not showing text on buttons" problem by changing MacOs theme. System Preferences>General>Light Mode.
You should have in mind that you may encounter other problems.
After a few hours messing with it I figured it out!
The Pipfile contained a reference to Python version 3.7
Therefore pipenv install was searching my machine for any 3.7 version of Python installed. The version it found was Homebrew's, which has Tk 8.5.9 statically linked.
By updating the Pipfile to require Python 3.8 my machine started pulling my system Python, which uses the dynamically linked Tk, which I had successfully updated to 8.6.9
This question already has answers here:
pylint can't find QWidget and QApplication
(3 answers)
Closed 3 years ago.
I've recently started to use PyQT5. However, I'm facing several errors which are being generated yet the application it self is still working. All of the errors are for undefined variables for PyQT related modules.
E.G. "Undefined variable 'QApplication' pylint(undefined-variable).
As im following a tutorial with no real expertise in PyQT or pylint im unsure as to what this is and how detrimental this is to my project. Can this be solved, if so how? if not, is there a possible work around?
Below is not the exact code I originally reported this error on (I'm only following a tutorial therefore none of it is complex code) however the following produces the exact same error which suggests it is indeed not the script itself and is likely a visual studio code or Pylint issue.
import sys
import time
# Self explanatory.
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
# Create QApplication Object. Something all applications must have one of.
app = QApplication(sys.argv)
The problem is not with the PyQT5. It is the problem with VS Code. The PyLint in your VS Code build can't understand the PyQT5 variables. It is because Pylint doesn't support Dynamic Modules like PyQT5.
https://github.com/Microsoft/vscode-python/issues/261
To solve the problem follow these rules:
Go to the VS Code User directory normally located at following path
Windows : %APPDATA%\Code\User\settings.json
macOS : $HOME/Library/Application Support/Code/User/settings.json
Linux : $HOME/.config/Code/User/settings.json
Open settings.json file.
Write following command at the end of the file:
{
"python.linting.pylintArgs": ["--extension-pkg-whitelist=PyQt5"]
}
Save the file.
Run your code and tell me if the error is fixed or not.
I have installed PyQt5 using the windows installer. I have tried creating some windows and stuff and it works great. Still, pycharm seems to not like PyQt5 very much, and is marking errors everywhere in my code.
As I said, PyQt5 is working great, but it's kind of annoying to have those errors which, by the way, i can not alt + enter + ignore them.
I guess it's just a matter of adding references or something to pycharm, but I have no idea how to do it and I have already spent 1 hour trying to look for solutions in stack-overflow, and none of them work. I have also tried re-installing it.
I am using windows 7 64 bits, python 3.4, and PyQt5 of 32bits because 64 didn't work for some reason.
I had similar problem because I had both PyQt4 and PyQt5 installed.
In general this can cause all sorts of problem, so the spyder-ide guys made the qtpy package, which gives an abstraction on top of the PyQt5/PyQt4/PySide.
Nowdays the qtpy is a standard library in the Anaconda distribution, and you can call it instead of PyQt5/PySide likes this:
from qtpy.QtCore import QFile, QFileInfo
from qtpy.QtGui import QIcon, QKeySequence, QPixmap
It solved me this specific problem in PyCharm.
I also have both 32 bit and 64 bit Python v3.5 and PyQt5 versions installed. That should not matter because I installed the 32 bit PyQt5 package in the 32 bit PI and the 64 bit PyQt5 package in the 64 bit PI. I installed the PyQt5 packages from Riverbanks's PyQt5 web site. Christopher Gohlke does not have them yet on his Windows extensions site, nor does PyCharm's PI dialog even list PyQt5 as an available package.
PyCharm does indeed incorrectly flag numerous warnings whether I choose the 32 bit PI or the 64 bit PI for the PyQt5 project I am working on. This appears to be a cosmetic bug only for PyQt5 code, since the code does run correctly, even if I run the code from PyCharm's Terminal window. Also, note that PyQt5 is not listed in PyCharm's PI settings dialog, even though Windows 10 File Explorer does indeed list the proper packages in the proper site-packages folder. Doing a PyCharm Invalidate/Restart does not help.
That said, you do not have to, nor should you, suppress warnings for everything. Just suppress warnings on a case by case basis only for PyCharm's incorrect PyQt5 warnings. You can do it like this:
def __init__(self):
# noinspection PyArgumentList
super().__init__()
In my case I needed in my PyCharm to go File -> Settings -> Project: MyProject -> Project structure and chose correct Project Interpreter
Another probable and easy means is to:
open the command prompt as an administrator
type in 'pip' (without the quotes)
type in: pip show PyQt5 (this shows you where PyQt5 has been installed.
follow the trace given to you from the command prompt. Now, open the folder 'site-packages' and copy every folder termed' PyQt5' to the 'lib' folder instead (ignoring those with '.. - info' is inconsequential).
In Pycharm or Visual studios, the red underline goes off and the problem of 'unresolved reference' is eliminated.
(New in python+kivy here).
Hi, I'm trying to get python with Kivy up in running and I just wanted to know if there's a way to run Kivy apps in PyCharm since I'm getting an error:
Traceback (most recent call last):
File "C:/Kivy/kivy/examples/tutorials/pong/main.py", line 1, in <module>
import kivy
ImportError: No module named kivy
when loading this file with pycharm, notice that that's the sample game out of the box, I can run the app via right click->sendTo->kivy.bat but I don't think that large scale apps actually do it that way -.- there must be a simpler(and hopefully more graphic) way to use Kivy, after a lot of asking to Dr. Google I give up, Thanks in advance!:)
BTW: My main interest is making apps that makes basic database requests and at the same time are GUI friendly , Kivy was my first option next to WX but if there are any suggestions they are welcome :)
I just put up a tutorial on how to setup pycharm & kivy on os x
Short Version for Windows (I assume this will work):
After you install kivy, you need to create a python interpreter for kivy - if you already had python installed, it's the wrong python to do Kivy work. Check C:/Kivy/kivy/ or the contents of kivy.bat to get the path to the python.exe distributed with kivy ( I found C:\Kivy141\Python\python.exe on one page, but that may be if you install kivy manually)
When you find it, your kivy project python interpreter needt to be that one.
Good luck!
With PyCharm on OSX I had the same problem and solved it by creating a VirtualEnv in PyCharm (see PyCharm docs for this) and some Kivy paths to the virtualenv. You can find this by selecting the VirtualEnv and select the tab "Paths".
You can probably find out the correct paths by inspecting the kivy.bat file. I did something similar on the Mac.
I wanted to include a picture to show my paths settings, but my Stackoverflow karma level doesn't allow this.
PyCharm 4.0 changed the answer, now it's just set some environment variables. I updated the Kivy Wiki for setting up PyCharm on OSX
For OSX 10.10.2, kivy 1.9.0, and Pycharm 5.0.2 (free Community Edition), the instructions at the link below worked for me:
Setting up Kivy 1.9.0 with PyCharm 4.5 EAP on OS X 10.10.3
Substitute PyCharm for PyCharm-EAP in the instructions(which only occurs once).
I entered each Environment variable separately, rather than pasting them in as one long string.
Pay attention to the titles of the windows where you enter things. The instructions tell you EXACTLY which window you should be looking at.
To anyone that may see this:
Follow the wiki guide to create the symlink.
In Pycharm, add a local file for the project interpreter, then click the "more" button, go to the pencil, and manually change the link to /Applications/Kivy.app/Contents/Resources/script . That's how I got mine to work, latest PyCharm CE, Kivy, Python 3.5, and El Capitan