How to use wxPython for Python 3?
Solution 1
You have two different pythons installed on your machine (3.4.1 and 2.7.5). Do not expect to be able to use one package installed in one python (wxPython 3.0.1.1 at python 2.7.5) automatically to be available in another python.
Additionally wxPython (classic) does not work for Python 3. You need wxPython Phoenix to be able to do that.
EDIT: The recommended way (by @RobinDunn) to install wxPython
(the Phoenix variety which will work on 2.7 and 3, now hosted on PyPI) nowadays is just doing:
pip install wxPython
If you have the developer version installed, just do the following beforehand:
pip uninstall wxPython_Phoenix
You can try to install one of the wxPython Phoenix snapshots in your Python 3.4.1. However, mind that Phoenix is not 1000% compatible with classic and you may experience the one or another hiccup when reusing classic code (but transitioning its doable and worth it).
You can find a complete explanation/description in the following wxPython wiki at the following link:
There are several important points:
that
pip
/setuptool
is new enough (> 6.x.x/> 12.x.x)that the builds are "inofficial", and thus
pip
refuses to install it: basically you need to add--pre
when installing with pip.that you waive SSL verification
--trusted-host wxpython.org
(no longer needed in modern versions where https now works properly).
Full command for Windows machines:
C:\python27\scripts\pip.exe install --upgrade --pre -f https://wxpython.org/Phoenix/snapshot-builds/ wxPython_Phoenix
Note that this will install wxPython Phoenix for Python 2.7.
Solution 2
To use wxPython with your Python 3.4x you need to use wxPython Phoenix - as others have pointed out. To install it you can do:
pip install -U --pre -f http://wxpython.org/Phoenix/snapshot-builds/ wxPython_Phoenix
Note the space after the last '/' and wxPython_Phoenix
Solution 3
As it seems, wxPython is not yet completely ported for Python 3, even though the version number might suggest that. This is why the wx modules aren't added to the sys.path
of Python 3.
You can either settle for using wxPython from Python 2.7 or have a look at this SO entry: Still no wxPython for Python 3 (or 3.3) yet? This is what @nepix32 suggested.
Alternatively, use another GUI library which works with Python 3. Here is a list.
Nick
Updated on July 09, 2022Comments
-
Nick almost 2 years
I installed
wxPython 3.0.1.1
, but I'm unable toimport wx
usingPython 3.4.1
. I am getting the following error:Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import wx Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'wx'
Nevertheless, I can
import wx
if I usePython 2.7
(the default installation in myOS X 10.9
):Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import wx >>>
How can I use wxPython for Python 3, and specifically for Python 3.4.1?
-
Nick over 9 yearsI don't know what is the proper link to the proper directory.
-
inirlan over 9 yearsDo you know your Python directory? Check that directory, go into Lib, then into site-packages. There should be a directory that starts with "wx-3.0". That's the one you're looking for. Is it in your sys.path?
-
Mike Driscoll over 9 yearswxPython 3.x has nothing to do with Python's naming conventions. It is following wxWidgets version numbering scheme. Also, the Phoenix port of wxPython does support Python 3, but it's not a complete port at this time.
-
Mike Driscoll over 9 yearsTo add a bit more to @nepix32's answer, Phoenix's core widgets are ported, but not all the custom widgets are. If you want to use wxPython's core functionality, then Phoenix should work for you.
-
Nick over 9 years@MikeDriscoll Can you give me any reference about Phoenix development status?
-
Mike Driscoll over 9 yearsSure. You can check out wiki.wxpython.org/ProjectPhoenix. I would also recommend looking through the wxPython-dev Google group.
-
jeromej over 7 yearsYou get a warning if you use the
http
version instead of thehttps
one. -
RobinDunn almost 7 yearsIn addition, there are builds of Phoenix on PyPI now, so a simple
pip install wxPython
will work. There are binaries for Windows and OSX, and pip will attempt to build from source on the other platforms. The snapshots folder is still used for upto daily builds when new commits are checked in to git, but the PyPI releases will be a little more stable and tested. -
Pygirl over 4 yearsgiving ERROR: No matching distribution found for wxPython_Phoenix