How to use wxPython for Python 3?

29,477

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:

Installing wxPython-Phoenix using pip

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.

Share:
29,477
Nick
Author by

Nick

Updated on July 09, 2022

Comments

  • Nick
    Nick almost 2 years

    I installed wxPython 3.0.1.1, but I'm unable to import wx using Python 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 use Python 2.7 (the default installation in my OS 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
    Nick over 9 years
    I don't know what is the proper link to the proper directory.
  • inirlan
    inirlan over 9 years
    Do 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
    Mike Driscoll over 9 years
    wxPython 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
    Mike Driscoll over 9 years
    To 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
    Nick over 9 years
    @MikeDriscoll Can you give me any reference about Phoenix development status?
  • Mike Driscoll
    Mike Driscoll over 9 years
    Sure. You can check out wiki.wxpython.org/ProjectPhoenix. I would also recommend looking through the wxPython-dev Google group.
  • jeromej
    jeromej over 7 years
    You get a warning if you use the http version instead of the https one.
  • RobinDunn
    RobinDunn almost 7 years
    In 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
    Pygirl over 4 years
    giving ERROR: No matching distribution found for wxPython_Phoenix