I've just installed wxPython with no problems. I'm on a Snow Leopard Mac using Python 2.6 and downloaded the corresponding wxPython version.
I've started by typing a very basic wxPython app, but I'm getting the following error:
ImportError: No module named wx
The code is the following:
import wx
class Application(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Hello World', size = (300, 200))
if __name__=='__main__':
app = wx.PySimpelApp()
frame = Application(parent = None, id = 1)
frame.Show()
app.MainLoop()
Am I using a wrong version of Python, is it a 32/64-bit situation bug? If so, how do I solve it?
EDIT: Forced python to run at 32-bit, the issue sustains.
You can't use wxPython in 64-bit mode. First, force Python to use the 32-bit binary:
defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
Then you can use the builtin Python and the builtin wxPython.
Ok, the problem was I was running python 2.5.
To all MacOSX users who get stuck trying to install wxPython or any other python module: make sure your Python version is the same as the requested by the module. The python version included in MacOS tends to be older than the last stable one.
Thank you to all who helped me out.
I'm pretty sure you're not supposed to use the standard MacPython install with wxPython, but I don't have a Mac, so I'm not sure...FYI: The cocoa build of wxPython DOES support 64-bit mode, though.
Related
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
I run a python application which uses a glade builder file for its GUI.
I recently migrated to a KDE desktop (Debian Wheezy). After installing the Gtk bindings with apt
(gir1.2-gtk-3.0) I tried to following error message when starting the Python
code:
gi._glib.GError: XXX.glade: required gtk+ version 3.10, current version is 3.4
How could I best solve this?
Do I need to downgrade Gtk from 3.4 to 3.1? And if yes how do I do that?
How do I find version 3.10 in the repositories?
Or is something wrongly configured? Maybe the Gtk version being fixed in the
glade file which I imported from a different system, whose Gtk version might
have been different (do not remember)?
Or any other suggestions?
I do not think source code is helpful in this matter, as the problem most likely is located outside of it, nonetheless some extract from it:
from gi.repository import Gtk, GObject, GLib
wTree = Gtk.Builder()
class Test_GUI:
def __init__(self):
self.builder = Gtk.Builder()
self.builder.add_from_file("XXX.glade")
self.window = self.builder.get_object("MainScreen")
self.window.show_all()
OK, the solution was to recompile the .glade builder file.
Somehow the version conflict was that the glade file was created on
a different system than it got used at.
Can you tell us wich program you try to use ? Can you Modify the source code to fit with your Gtk version ? Does it work ?
The upgrade from Gtk 3.4 to 3.10 is not possible (with aptitude or apt-get); Gtk 3.10 can't be found in the official repository of debian (correct me if i'm wrong), see this link
However you can install a later unstable version, see this link (It's not recommand too).
dialog = gtk.FileChooserDialog("Open..",
None,
gtk.FILE_CHOOSER_ACTION_OPEN,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
I want to use the above code for file browsing- but when I give the following import
import pygtk
pygtk.require('2.0')
import gtk
I get Error: No module named 'pygtk'
Do I need to give pygtk as a module inside my application folder? Do say with steps. Thank you.
pygtk is the old and deprecated gtk Python api. Do not use it unless you have a legacy application. The correct way nowadays is to use GObject-introspection to use Gtk3 from Python. Which is also really awesome as it makes Python a first-class supported language, with no wrappers necessary.
from gi.repository import Gtk
dlg = Gtk.FileChooserDialog()
dlg.show()
You should look at this: http://rox.sourceforge.net/desktop/node/245.html
It shows some problems. Good luck on fixing it :).
Edit:
This has lots of info on pip install (windows): How do I install pip on Windows?
I am trying to install wxPython on my Ubuntu 12.10 but with no success. I have gone through all the answers given on this website.
Can someone please help me in this or point me in the right direction.
Initially, I tried http://wxpython.org/BUILD.html but then I came to know that it is in the repository, I ran "sudo apt-get install install python-wxgtk2.8", it installed without any error but then, when I run it, it is still unavailable. I guess I am doing something in the running step.
Also, although it is working in Eclipse using PyDev, but I am getting this warning " LIBDBUSMENU-GLIB-WARNING **: Trying to remove a child that doesn't believe we're it's parent."" after I close the application and the status bar is also not working,
Here is my code:
import wx
class naman(wx.Frame):
def __init__(self,parent,id): # #ReservedAssignment
wx.Frame.__init__(self,parent,id,'Frame aka Window', size=(300,200))
panel=wx.Panel(self)
statusbar=self.CreateStatusBar()
menubar=wx.MenuBar()
first=wx.Menu()
second=wx.Menu()
first.Append(wx.NewId(),"New Window", "This opens a new window")
first.Append(wx.NewId(),"Open...", "This will open")
second.Append(wx.NewId(),"Undo", "This will undo")
second.Append(wx.NewId(),"Redo", "This will redo")
menubar.Append(first,"File")
menubar.Append(second,"Edit")
self.SetMenuBar(menubar)
if __name__=='__main__':
app=wx.PySimpleApp()
frame=naman(parent=None,id=-1)
frame.Show()
app.MainLoop()
If someone can tell why I am getting this warning and why status bar is not working, that would be great too!! Then, I can continue working in eclipse itself and don't bother about wxPython.
PS: I have Python2.7 and Python3.3 already installed.
Thanks in advance.
You need to install wxPython Phoenix, not 2.8. The 2.8 series and the 2.9 Classic series are only Python 2.x compatible. You'll have to grab a Phoenix snapshot to build against as it is the only version that is Python 3 compatible. You can get one here:
http://wxpython.org/Phoenix/snapshot-builds/
Note that Phoenix is very beta in that it only supports the core widgets currently. Most of the custom widgets, like those in wx.lib, are still being ported. See http://wiki.wxpython.org/ProjectPhoenix for more information.
I have an application which depends on PyGTK, PyGobject, and PyCairo that I built to work on Linux. I want to port it over to windows, but when I execute import gobject I get this:
Traceback (most recent call last):
import gobject
File "C:\Python26\lib\site-packages\gtk-2.0\gobject\__init__.py", line 30, in <module>
from gobject.constants import *
File "C:\Python26\lib\site-packages\gtk-2.0\gobject\constants.py", line 22, in <module>
from _gobject import type_from_name
ImportError: DLL load failed: The specified procedure could not be found.
This appears to be caused by the switch from building using MinGW to Microsoft Visual Studio, as documented Python Bug 3308 (closed: wontfix).
Is there any way to install PyGTK/PyGObject in a way that will work with Python 2.6 on Windows, without having to recompile one or the other from source?
I have it working fine, and it didn't give me much trouble, so we know it can be done...
Keep in mind you will probably need all of the following installed on your Windows machine:
PyCairo ( http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/ )
PyGobject ( http://ftp.gnome.org/pub/GNOME/binaries/win32/pygobject/ )
PyGTK ( http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/ )
Unofficial x64 versions of the above 3 items are available here -- However, I cannot vouch for nor recommend them!
and of course
the GTK+ Runtime ( http://ftp.gnome.org/pub/GNOME/binaries/win32/gtk+/ or http://ftp.gnome.org/pub/GNOME/binaries/win64/gtk+/ )
I suspect in your case that the PyGTK libraries are not finding your GTK+ Runtime directory where the DLLs are. You should have the environment variable GTK_BASEPATH set to the directory of your GTK+ Runtime (usually C:\GTK).
Please also see the PyGTK-on-Windows FAQ
Now, if you're trying to compile the PyGTK'ed Python with Py2EXE, that's a bit more complicated, but it can be done as well...
The PyGTK all-in-one installer has been updated recently:
http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.22/
This will install PyGTK, PyGObject, PyCairo, PyGtkSourceView2, PyGooCanvas, PyRsvg, the gtk+-bundle and Glade. It is absolutely everything necessary to be able to successfully import gobject, import gtk, etc, without DLL problems.
for 64 bit Windows users see
http://digitalpbk.blogspot.in/2012/03/installing-pygtk-pypango-and-pycairo-on.html
Above steps will give Invalid DLL error on 64 bit.
u should have pygtk,pycairo,pygboject and the gtk+ runtime...
see this for an all in one installer
http://aruiz.typepad.com/siliconisland/2006/12/allinone_win32_.html
Be careful about installing PyGTK bundle pack if any one planning to run PyGTK through embedded interpreter and the C/C++ code is already using GTK. PyGTK bundle pack does not add its GTK runtime to PATH.
In such case possibly the C code will take GTK from PATH (as probably you have already installed GTK bundle pack) and Python will use separate set of GTK runtime libraries.
Therefore in my case either C GUI or Python GUI used to run properly and used to conflict while running together.
As I use Psychopy as my base python collection, to solve this problem I have just installed PyGTK PyGTK, Pycairo, Pygobject on top of Psychopy.
Apart from using only one set of GTK runtime I had to initialize GTK in my C code through PyGTK (not by gtk_init (&argc, &argv) in my C code) after initializing python interpreter.