I want to develop with these tools:
I installed PyCharm, but up to now Python and g
There two ways of doing what you want.
But first, lets set something straight, when you say gtk, you don't specify GTK-2 or GTK-3. GTK-2 python bindings aka PyGTK is quite an old package (but still possible to use). GTK-3 python bindings, included in PyGobject are, I imagine, what you want.
So, I'll start with the more restrictive one.
You can install PyGObject through the PyGI AllInOne installer. This is a .exe
installer that comes with a lot of stuff, from gtk3 and gstreamer, to gnome applications like Glade and Gedit, to non gnome applications. Why do I say it's restrictive? It only works with Python from version 2.7+ to 3.4+ (32 or 64 bits). So if you want to use Python 3.6, you can't use this. And it seems that it will never be updated.
The other way is using MSYS2, like someone advised before. This option lets you use the current versions of Python supported by mingw-64 repository. Which I believe right now is Python 3.7.
You can install following the steps as described in the PyGObject site. Or the way explained below (CLion).
I don't know how to use PyCharm with a MSYS2 python installation, but a bit of googling led me to this tutorial for CLion. Maybe there's an analog for PyCharm.
use 32 or 64 Bit version of Python?
You can pick any, it doesn't really matter.
how to install gtk for python (pip or exe)?
You should able to install it with pip: pip install pygtk
.
Use virtual env in PyCharm or use "Existing Interpreter"?
If you don't know, you probably need "Existing interpreter".
There should be an option to select path to your python.exe
It should be there: Menu->File->Settings->Project->Project Interpteter
use 32 or 64 Bit version of Python?
The documentation suggests 32 bit for msys2, so this is the safest. However, if you have a 64 bit computer, the 64 bit version could allow some more processing power for larger tasks.
How to install gtk for python (pip or exe)?
Most definitely using the .exe available from this source. This tool is a package manager for Windows that will let you install gtk and its dependencies. Instructions there will walk you through setting up the default environment, then from that environment run pacman -Suy
and pacman -S mingw-w64-i686-gtk3 mingw-w64-i686-python2-gobject mingw-w64-i686-python3-gobject
.
Use virtual env in PyCharm or use "Existing Interpreter"?
Using the 'Existing Intepreter' is a must for this method of installation, as you need to point PyCharm to your msys2 Python, which actually has gtk available. It should be located at C:\msys64\bin\python.exe
. Keep in mind that you might not be able to run some scripts directly through PyCharm this way, as Python will be running through a virtual bash-like environment. Save your scripts in the C:\msys64\home\<username>
directory so that you can run them easily when you open msys2 with python3 script.py
.
update a couple years later, in case someone else is stumbling down this path - pyGTK/pyGObject now only installs via msys2/mwing. This causes problems with several things.
Firstly, the whole msys python is incompatible with the more normal pip way of distributing tools. From what i've seen, most python tools are shared via pip and wheels now. I'm working with a network messaging library (pynng) which is available via source and pip. I really dont want to go thru the rebuild-from-source thing. That is so last century unix mods.
Secondly, when i tried using mwing's python with pyCharm it failed, saying there were various permission errors. mwing seems to like making things restricted. Maybe if i ran pyCharm as admin it might work.
Maybe I will go with the original post's update and ditch GTK for pyside/QT. I'm not really happy with the look/feel of GTK anyway. It was just the simple solution for the rPi project I was doing.
**Step 1:** Download the Python 3 Installer
Open a browser window and navigate to the Download page for Windows at python.org.
**Step 2:** Underneath the heading at the top that says Python Releases for Windows,
click on the link for the Python 3.x.x.scroll to the bottom and select either
Windows x86-64 executable installer for 64-bit or Windows x86 executable installer
for 32-bit.
The difference between 32bit and 64bit:
If your system has a 32-bit processor, then you should choose the 32-bit installer. On a 64-bit system, either installer will actually work for most purposes. The 32-bit the version will generally use less memory, but the 64-bit version performs better for applications with intensive computation.source
**Step 3:**For PyCharm installation follow link
Using Existing Interpreter (pre-installed python)
**Step 4:**Launch PyCharam, go to settings and click on project interpreter, browse path python3 installed in above step 2.
Step 5: how to install PyGTK or any library in PyCharm selected python environment. Follow step 4 and then click on green + sign in search bar just name the library you want to be installed
.
Here onwards you can install any library just follow step 5, instead of doing pip install library-name each time.
You can also use the virtual environment option, the advantage is that some libraries can work only with the specific version of python.so you can set different version of python in different virtual environments on the same machine.
virtualenv really shines when you have a number of projects and don't want them to all share the same Python installation. For example, you could have two projects with conflicting requirements. virtual environment set-up
For the latest version of PyGTK instead of Step 5 follow this link