Spyros Maniatopoulos
Spyros Maniatopoulos

Reputation: 404

wxmac image not found (Python 2.7.5, OS X)

I had "brew installed" wxmac back in 2012. Recently, I "brew upgraded" and then "cleaned up". Since then, I can no longer import wx:

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
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/wx-2.9.4-osx_cocoa/wx/__init__.py", line 45, in <module>
    from wx._core import *
  File "/Library/Python/2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py", line 4, in <module>
    import _core_
ImportError: dlopen(/Library/Python/2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core_.so, 2): Library not loaded: /opt/local/lib/libwx_osx_cocoau_xrc-2.9.4.0.0.dylib
  Referenced from: /Library/Python/2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core_.so
  Reason: image not found

Looks like I now have a version newer than 2.9.4:

brew install wxmac
Warning: wxmac-3.0.1 already installed

Looking at my Python installation, these are the relevant files:

ls /Library/Python/2.7/site-packages/
wx
wx-2.9.4-osx_cocoa
wx.pth
wxPython_common-2.9.4.0-py2.7.egg-info
wxversion.py
wxversion.pyc

I'm suspecting that "brew cleanup" removed my older, but working, version of wxmac. Now, either the wxmac version or some symlink is causing the current problem. How should I go about fixing or figuring it out?

Upvotes: 0

Views: 695

Answers (1)

Tim Smith
Tim Smith

Reputation: 6349

It looks like wxpython files were copied from or symlinked to or just referenced from /Library; Homebrew will never install files to /Library and doesn't know how to manage them if you or an installer placed them there. To use Homebrew wxpython, please remove everything wx-related from your /Library site-packages folder and brew install wxpython in addition to wxmac.

To use wxpython with system Python, you need to tell Python that your Homebrew site-packages folder is a special "site-packages" folder; having it in sys.path is not enough, because wxpython relies on .pth files that are only processed in special folders. To do this, you can run:

mkdir -p ~/Library/Python/2.7/lib/python/site-packages
echo "import site; site.addsitedir('$(brew --prefix)/lib/python2.7/site-packages')" >> ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth

Then, import wx should work.

Upvotes: 1

Related Questions