Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use wxPython for Python 3?

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?

like image 486
Nick Avatar asked Oct 08 '14 07:10

Nick


2 Answers

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.

like image 88
nepix32 Avatar answered Sep 29 '22 07:09

nepix32


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

like image 34
Werner Avatar answered Sep 29 '22 07:09

Werner