Unable to import wxPython (Mac)

I thought I would switch from using Tkinter to wxPython, but I have problems. All I get is:

>>> import wx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named wx

I installed wxPython. When I run the uninstaller, I clearly see that wxPython IS is installed:

  1.  wxPython3.0-osx-cocoa-py2.7                 3.0.0.0

Enter the number of the install to examine or 'Q' to quit: 

When I start Python, I see that my version should match the wxPython version:

Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

I'm on OS X 10.7.5 32-bit.

Any help would be awesome! :)

+3
source share
4 answers

Macs can have several versions of Python. Are you sure you installed wxPython for the same python that you invoke with the interpreter?

which python , python wxredirect.pth site-packages, wxPython. ( wxredirect.pth.)

...

> which python2.6
/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6

> more /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/wxredirect.pth
import site; site.addsitedir('/usr/local/lib/wxPython-3.0.0.0/lib/python2.6')
#import site; site.addsitedir('/usr/local/lib/wxPython-2.9.1.1/lib/python2.6')
#import site; site.addsitedir('/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.6')

, btw, wxredirect.pth, wxPython, .

+2

. brew install wxpython, mac. , . , , :

   brew install tbb
   Downloading https://homebrew.bintray.com/bottles/tbb-2017_U7.sierra.bottle.t
   ############################################################ 100.0%
   ==> Pouring tbb-2017_U7.sierra.bottle.tar.gz
   ==> Caveats
   Python modules have been installed and Homebrew site-packages is not
   in your Python sys.path, so you will not be able to import the modules
   this formula installed. If you plan to develop with these modules,
   please run:

   mkdir -p /Users/ningrongye/.local/lib/python2.7/site-packages
   echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-        
   packages")' >> /Users/ningrongye/.local/lib/python2.7/site-
   packages/homebrew.pth`

, , , .

ningrong

+1

Python 2.7 3.7. /usr/local/bin/ Python 2.7 3.7, pip.

wxPython pip3

pip3 install -U wxPython

Python3

myname$ python3
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.version()
'4.0.4 osx-cocoa (phoenix) wxWidgets 3.0.5'

0

, brew 2.7:

brew link --overwrite python@2
0

All Articles