14

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?

nbro
  • 15,395
  • 32
  • 113
  • 196
Nick
  • 10,309
  • 21
  • 97
  • 201
  • Maybe you need to add the module's location manually to your `sys.path`: `sys.path.insert("/location/of/wx")` Here is a more detailed description: http://stackoverflow.com/questions/279237/import-a-module-from-a-relative-path – jotrocken Oct 08 '14 at 07:27
  • @jotrocken How can I do it in such a way it will be permanent? – Nick Oct 08 '14 at 07:29
  • http://stackoverflow.com/questions/3402168/permanently-add-a-directory-to-pythonpath – jotrocken Oct 08 '14 at 07:31
  • This is just a workaround, though. So I wont post it as an answer. Refer to the package's distributor if you need a clean solution. Installing it *should* put the packages in the correct location or extend the paths correctly. – jotrocken Oct 08 '14 at 07:34
  • @jotrocken thanks, the problem is I don't know the correct location where to install wx for python 3. Do you have any idea? – Nick Oct 08 '14 at 07:47
  • Default should work, if it is supposed to support Python 3. But it's not. See my answer. – jotrocken Oct 08 '14 at 11:06

5 Answers5

16

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.

nepix32
  • 3,012
  • 2
  • 14
  • 29
  • 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. – Mike Driscoll Oct 08 '14 at 13:04
  • @MikeDriscoll Can you give me any reference about Phoenix development status? – Nick Oct 10 '14 at 11:47
  • Sure. You can check out http://wiki.wxpython.org/ProjectPhoenix. I would also recommend looking through the wxPython-dev Google group. – Mike Driscoll Oct 13 '14 at 13:55
  • 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. – RobinDunn Jun 01 '17 at 18:21
7

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

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
Werner
  • 2,086
  • 1
  • 15
  • 14
2

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.

Community
  • 1
  • 1
jotrocken
  • 2,263
  • 3
  • 27
  • 38
  • 1
    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 Oct 08 '14 at 13:03
0

Check your sys.path in an interpreter :

import sys
sys.path

If you don't have the proper link to the proper directory, it won't work.

Also, check Lib/site-packages in your python directory, to make sure wx is properly installed on your python 3. (there should be a directory starting with "wx-3.0")

inirlan
  • 18
  • 1
  • 8
  • I don't know what is the proper link to the proper directory. – Nick Oct 08 '14 at 07:51
  • 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? – inirlan Oct 08 '14 at 07:55
0

Perhaps the solutions given earlier worked before. But what worked for me today (June 1, 2017) was:

pip install - U - - pre - f https://wxpython.org/Phoenix/snapshot-builds/ wxPython

Always check the Readme.txt for this one...

Seyi Shoboyejo
  • 489
  • 4
  • 11