How do I link PyCharm to PyQt4? - pyqt4

I use PyCharm 2016.2.3 (32-bit), Python 2.7.12 (32-bit), PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x32, Windows 7 Home Premium.
I would be grateful for the procedure to link PyCharm to PyQT4. I'm not a techie.
I linked to the Python interpreter using File > Settings > Project Interpreter, by simply pointing to "python.exe"
For PyQt4, I can see the folder in
C:\Python27\Lib\site-packages\PyQt4
But which file do I actually "point to"?
Thanks.

Here's how I solved this for Python 2.7.12 and Python 3.4.4:
File > Settings > Project > Project Interpreter > <Python version>
Double-click setup tools
In Search, type PyQt4
In left pane, don't select PyQT4. This will give the error
Could not find a version that satisfies the requirement PyQt4
Instead, select PyQt4_windows_whl. For me, this was successful.
Test in editor by typing:
from PyQt4 import QtGui
As soon as I typed
from P
PyQt4 appeared in the dropdown.
As soon as I typed
from PyQt4 import Q
QtGui appeared in the dropdown.
I'm no expert, so I don't know if these tests are conclusive.

Related

Cannot import Tkinter on visual studio code?

Ok, I am having a weird issue going on. From what I understand Tkinter is supposed to be built in with python 2 and 3.
I can import and use Tkinter just fine in my terminal under python3 as well as with IDLE3. However, when I try to import Tkinter in Visual Studio Code I get an "ImportError: No module named 'tkinter'.
The same issue was happening in Pycharm also but I had my interpreter set to the same as my terminal and not a project-specific interpreter.
I have tried the following:
import tkinter
from tkinter import *
try:
import tkinter
except ImportError:
import Tkinter as tkinter #Even though I'm using python3
None of this is working, Any idea why?
Also I am using Linux Mint.
I've been stuck with the same issue for weeks now where my VSC says there are no tkinter module but in shell and terminal it runs fine.
Solution: I found out that in the left buttom corner there is an interpreter that runs as Python 2 just click and select Python 3
In windows you could have selected to not install the needed tkinter components when python was installed (its optional in the installer).
Try running the installer again, and make sure these components are selected.
If your interpreter is PHP2 it is spelled "Tkinter" in the code. (uppercase)
If your interpreter is PHP3 then you should spell it like "tkinter"
When you were installing python there is a option. Install tkinter and ide just check it and then reinstall python after that close and open vs code. Here you go!

Pygame in PyCharm (or Visual Studio)

Where am I going wrong about with Pygame in PyCharm??
1 I have installed Pycharm and its works
2 I have installed Python and Pygame. I have ran "python -m pygame.examples.aliens" in the cmd and the game loads.
3 I have anaconda3 on my computer and that works i.e. you can use the files in the library
4 When I go to Pycharm and type "import pygame" I get an error line
5 So I try and change the interpreter to where Pygame is located and it does not work.
How do you get Pygame into an interpreter. Or what the hell am I missing.
The package will be available only for the version you've installed, python2 or python3.
It looks like you installed pygame into python2, if this command works in cmd:
python -m pygame.examples.aliens
To check or change the default interpreter used in PyCharm:
-menu File > Build, Execution, Deployment > Console >
Python Console > Python Interpreter
By modifying this you don't change the interpreter in your current projects, you can create a new project to check if Pygame is working now.
In your current projects, you can see what interpreter is enabled, in the top right corner toolbar:
-name of the file > Edit configurations > Python interpreter
Maybe you can install Pygame in Python3 to avoid the issue

PyCharm Import Error: Claims 'matplotlib' is not a package, but works successfully in IDLE

Happy October everyone,
I've successfully downloaded modules before using either the pycharm installer or pip through the command screen, but for some reason when installing matplotlib pycharm cannot recognize it. I've uninstalled and reinstalled, I've installed through both methods, I've followed past similar questions asked on this site which make sure that you have the same interpreter and that it was installed in the right folder (pycharm error while importing, even though it works in the terminal).
So, here's the whole problem. Here's is the simple code, submitted into both pycharm and IDLE:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[2,1,3])
plt.show()
When submitted into IDLE, my plot appears. When submitted into pycharm, the following error appears:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/PythonProject/matplotlib.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\PythonProject\matplotlib.py", line 1, in <module>
import matplotlib.pyplot as plt
ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I am currently running Python 3.4, PyCharm 2016.2.3, and my matplotlib folders are indeed in my site-packages folder inside my Python34 folder. Also for further verification:
PyCharm installation
Please help I've become frustrated since this is the only module I've run into trouble with. I've scoured StackOverflow and related websites to help, I've made sure I have all the requirements, etc.
I guess if you named your current writing python module as matplotlib.py.That cause the python load your current writing module instead of the actual matplotlib.py, which triggers an error.
I recommend you to use virtualenv. Is not strictly necessary but is good for dividing your project environments.
This is how I tested matplotlib on my Windows 10 installation, hope it helps.
Be sure that you have the python 3 installation folder listed in your Windows PATH environment variable, should be already listed if you checked "Add Python 3.5 to PATH":
You need also to set the Scripts folder in your PATH environment variable usually should be this path:
C:\Users\<your username>\AppData\Local\Programs\Python\Python35\Scripts
If you don't do that you have to prepend python -m to every command below like this: python -m <command>, so the command below would be python -m pip install virtualenv. I prefer the first solution.
To test matplotlib on Pycharm I've used virtualenv, here is how; first install virtualenv:
pip install virtualenv
Then you create your virtual environment in a folder of your choice, in my case I used python_3_env_00:
virtualenv python_3_env_00
After that you can activate you python 3 virtual environment:
python_3_env_00/Scripts/activate.bat
Now you should see in your command line the active virtual environment (python_3_venv_00), like this:
Now you can install matplotlib:
pip install matplotlib
Fire up PyCharm and add your virtual environment as you project interpreter, go to File->Settings search for Project Interpreter click on the gear icon and Add Local and set the path of your virtual environment, should look like something like this:
Test it:
import sys
print(sys.path)
run this code in where the import worked, and run it in the Pycharm project. Compare the lists. Find out which path that is not present in Pycharm sys.path.
Before importing pyplot, append the missing path to sys.path.
import sys
sys.path.append("the path")
import matplotlib.pyplot as plt
Does this work?
Please follow below steps if you are still getting an error:
If you are using PyCharm, it automatically create virtualenv.
Ensure Scripts path is set into PATH
C:\Users\<Username>\AppData\Local\Programs\Python\Python37-32
Then open PyCharm and go to File-> settings. Search for Project Interpreter. You will see window like this
sample image
Click on setting icon -> Existing Environment -> click on ... give below path
C:\Users\Krunal\AppData\Local\Programs\Python\Python37-32\python.exe
Click on Apply -> ok and you are good to go.
After installing matplotlib When I was trying to use matplotlib.pyplot it was giving error module not found.
I browsed some white papers and found out that we also need to install scipy library to use the matplotlib so I used the below in my command prompt
python -mpip install scipy
Restarted my kernel session.
It worked!!!
I was also facing issue while importing matplotlib but it got resolved and now I am able to use it from pycharm as well.
Please make sure you should have visual c++ 14 installed in your system.
2.If you have more than two python version installed on your system then please install matplotlib from both the version.
Eg. pip install matplotlib
pip3 install matplotlib
If matplotlib is working from python idle then please check whether you are using correct interpreter in pycharm or not and try to choose pythonw.exe path from your installed location.
Hope this will help, Please do let me know if you are still facing issue.
I had similar issue but I solved it very easily on pycharm 2019.3.2. In case anyone looking for an easier solution:
I just opened the terminal window on pycharm and typed pip install matplotlib and it was all good to go. Every project has its own virtual environment. Opening terminal window of IDE cds to project directory by default. So the installing command was enough.

Sublime Pylint PyQt4 Module has no member

I'm using Sublime-Text3 with SublimeLinter + SublimeLinter-pylint installed.
Everything works as expected, except for pylint "scanning" PyQt4
from PyQt4 import QtCore, QtGui
works OK. Pylint detects QtCore and QtGui, but if
button = QtGui.QPushButton()
layout = QtGui.QVBoxLayout()
pylint sets red underlines and tells that
PyQt4.QtGui has no "QPushButton" member
Is there any way to fix this error or maybe ignore PyQt in SublimeLinter?
recent versions of pylint don't load extensions modules anymore (i.e. compiled code not written in pure python), unless they are listed using the extension-pkg-whitelist option. This is because loading extensions modules requires to actually load the code which may trigger undesired side effects.
In your case, pylint --extension-pkg-whitelist=PyQt4 <your module> (or using equivalent entry in the config file) should fix your problem.
Found the solution, thanks to sthenault
Step by step.
Generate rc file
pylint --generate-rcfile > pylint.rc
Replace the line
extension-pkg-whitelist=
by
extension-pkg-whitelist=PyQt4
Sublime
Preferences -> Package Settings -> SublimeLinter -> Settings - User
"pylint": {
[..another settings..]
"rcfile": "/path_to_rc/pylint.rc",
}

Why PyCharm can't import Gtk? [duplicate]

I'm using PyCharm 2.5 on Ubuntu 11.10, trying to develop an application using PyGObject 3.0 on Python 3.2.2. I've installed the Ubuntu package python3-gobject, and when I run my code, it works exactly as expected.
However, PyCharm can not seem to find any of the PyGObject modules. It says Unresolved refrence: 'Gtk' when I hover over Gtk in my import statement, and of course none of the auto-completion works.
This is my code:
#!/usr/bin/env python3
from gi.repository import Gtk
win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
I've even tried making a python virtual environment and then installing PyGObject from source into it, and then even tried making symlinks from all the .py files in site-packages/gi/overrides to site-packages/gi/repository, all with no luck.
Any advice would be greatly appreciated!
Position the text cursor inside the redlined Gtk in:
from gi.repository import Gtk
hit Alt + Enter and choose "Generate stubs for binary module"
In Gtk+ 3 Python bindings to binary modules are generated dynamically using *.typelib databases. The dynamic importer for accessing all the modules is located in gi.repository. PyCharm cannot detect these modules using its code insight, because they require special handling.
I've filed a feature request for this issue: PY-6932. Feel free to vote for it.

Resources