Why PyCharm can't import Gtk? [duplicate] - python-3.x

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.

Related

Why does Tkinter work in the terminal but not in Pycharm?

Using Pycharm on Linux mint.
I installed the "future" package for the python interpreter which I'm using. Heres the script.
from tkinter import *
top = Tk()
top.mainloop()
Didn't work. It returns "ModuleNotFoundError: No module named 'tkinter'". Tkinter is infact installed. "python3 -m tkinter" confirms it. And when I compile the same code in the terminal, it displays.
As Bryan says, you're probably not using the Python version you think you're using. PyCharm tends to install its own version of Python. Once you have more than one version of Python installed, things get trickier.
To see what's happening, try running this script:
import sys
print(sys.executable, sys.version)
Or run those similar commands from the command line. That should help clarify matters.
The sys.executable will show you the full path to your Python executable. Great for seeing where the used Python installation is located.
I don't use Python on Linux, but perhaps one of your Python installations is version 2, in which case you would need to use:
from Tkinter import *
which is another way to confirm that the Python is version 2 rather than 3. If this is the case, you'll want to move to Python 3. I don't think anyone writes new projects in Python 2 anymore. It's defunct, purely legacy.
It's also possible that Python is installed on Linux without Tkinter. There are other posts on how to install Tkinter on Linux. For instance, you can check out ImportError: No module named 'Tkinter'
Thanks guys for the help I really appreciate it. But I found out the problem was because of Linux Mint's Software Manager. I initially downloaded pycharm using said software manager but it didnt work which is why I created the post. Then I deleted it, and downloaded pycharm through the tar.gz file from the jetbrains website. After doing that, it seems to work.

SDL2 module not found

I'm using python 3.7.9 and I have this code:
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello world')
if __name__ == '__main__':
MyApp().run()
And I get this error:
Yes, I've tried reinstalling all kivy libraries multiple times, I've tried reinstalling Python but I still get this error.
My project settings:
My configurations:
I've even found it in 'External Libraries' folder:
I've tried to fix for literally 3 hours now and I'm too frustrated so I'm asking you guys. Thank you in advance.
First, forget pycharm, follow the kivy install instructions and see if you can run a kivy app via python from the command line. If you can't, debug this without the pycharm environments getting in the way.
If you can install and run kivy outside of pycharm, then your only problem is that you haven't installed it correctly within whatever python environment pycharm is using. I don't know how you configure it, but you'd need to make sure kivy and its dependencies are installed in that environment.

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!

Use PyQt5.QtWebEngineWidgets on Windows: is it possible?

I am trying to build an app in PyQt5 (version 5.6+) in Python 3.6. It contains a web browser, using QtWebEngineWidgets.
It works fine on Mac, however, there are problems on Windows.
When I run the code on Windows and import the module:
from PyQt5 import QtWebEngineWidgets
I get the following error:
ImportError: cannot import name 'QtWebEngineWidgets'
Now, reading some forums it looks like PyQt5.QtWebEngineWidgets is not available for Windows, yet. Is it correct?
How can I have a web browser window, then?
I found online I could use QtWebKit, but according to here it seems QtWebKit was removed in Qt5.6.
So what? Do I have to downgrade PyQt version?
I can't go under 5.6 in Python 3.6 anyway. Do I have to change Python version as well?
you can try one of these solution ,
install old version :
pip install PyQt5==5.11.3
or install :
pip install PyQtWebEngine
u can download PyQt5.6 from here:
https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.6
QtWebKit got deprecated upstream in Qt 5.5 and removed in 5.6. Beacuse The QtWebEngineWidgets module is better than QtWebkit.
The example directory has many examples about QtWebEngineWidgets
Yes, its possible to use QtWebEngineWidgets on Windows.

PyCharm 2017.1, No module named 'kivy'

I could use (troubleshooting)help with getting Kivy imported in PyCharm. I am using:
Anaconda with Python 3 on 64-bit Windows 10 Pro
PyCharm 2017.1
Packages: NumPy, SciPy, BeautifulSoup, Pandas, Scrapy, Pattern, NetworkX, NLTK, scikit-learn, Selenium
I have installed Kivy following the instructions at https://kivy.org/docs/installation/installation-windows.html#installation
As evident from the screen shot, no errors occurred.
Still, when I run "import kivy" from PyCharm I get "ModuleNotFoundError: No module named 'kivy'".
I ran through the installation with someone on the #kivy channel and was assured that kivy is successfully installed.
When I pass import kivy; print(kivy.file) to the interpreter (opened from the CMD command line), I get returned among others:
C:\Users\Steve\Anaconda3\lib\site-packages\kivy\__init__.py
Someone on #kivy suggested I check where PyCharm looks for kivy. How do I figure that out?
I'd appreciate any suggestions to identify the problem / resolve my issue.
Indeed, the installation of Kivy went fine. The problem turned out to be that I had to select the correct (updated) interpreter in the PyCharm settings.

Resources