Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wxPython 2.9 on Mac Os X

I am using Enthought Python Distribution (7.2, 64-bit). It comes without wxPython (which is quite important). However, wxPython-2.9 seems to support 64-bit Cocoa interface, so I gave it a try. Actually, it all went good: the command

python build-wxpython.py --osx_cocoa --mac_framework --install

successfully compiled, and even got into EPD site-packages. However, a simple wxPython code

import wx
wx.App()

fails with the following error:

This program needs access to the screen.
Please run with a Framework build of python, and only when you are
logged in on the main display of your Mac.

Can you give me some advice how to cure this? EPD is clearly a Python Framework (i.e., looking at /Library/Frameworks/EPD64.framework and /Library/Frameworks/Python.framework convinces me in it) but this wxPython build does not know about that. The version of wxPython is 2.9.3.1

like image 942
Ivan Oseledets Avatar asked Apr 30 '12 15:04

Ivan Oseledets


2 Answers

Using a wrapper script like this should setup your environment in such a way that wxPython works correctly:

#!/bin/bash

# Real Python executables to use
PYVER=2.7
PYTHON=/Library/Frameworks/Python.framework/Versions/$PYVER/bin/python$PYVER

# Figure out the root of your EPD env
ENV=`$PYTHON -c "import os; print os.path.abspath(os.path.join(os.path.dirname(\"$0\"), '..'))"`

# Run Python with your env set as Python's PYTHONHOME
export PYTHONHOME=$ENV
exec $PYTHON "$@"

Just dump it in a file, give it executable permission and use it to launch your wxPython app instead of the python executable.

like image 41
gregarmer Avatar answered Oct 11 '22 05:10

gregarmer


It's because you install wxpython with system python. so you can just modify the main.py or whatever the other main point your project defined, add at the head like the following:

import site
site.addsitedir("/Users/jazz/.pyenv/versions/py27/lib/python2.7/site-packages/")

and then run with /usr/bin/python

like image 92
jiahut Avatar answered Oct 11 '22 05:10

jiahut