wxPython 2.9 on Mac Os X
Asked Answered
E

3

9

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

Edmonton answered 30/4, 2012 at 15:51 Comment(4)
Has anyone found a solution to this problem yet?Joeljoela
I don't think so. I switched to PySide though, which works fine for my needsEdmonton
Is PySide installation straightforward for EPD64 on OSX 10.7?Joeljoela
@Joeljoela I have an academic version of EPD (which is non-Free, but if you work in a degree-granting institution, you can get it for free), and PySide is included in it. It is not in the EPD Free, but I suppose that you can just install PySide from sources as usual.Edmonton
P
2

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

Prosthodontics answered 20/3, 2015 at 8:39 Comment(0)
F
1

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.

Fujio answered 4/10, 2012 at 22:7 Comment(3)
Can you please elaborate on how this solution works and why there was a problem in the first place using wxPython 2.9 with EPD?Joeljoela
This solution did not work for me. Setting PYTHONHOME did not change the error message given in the original question.Joeljoela
@Joeljoela This solution did not work for me also. It uses the Apple Python which is not the EPD one.Edmonton
G
0

I use anaconda python distribution and encountered the same problem as you described. Namely, "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." I don't know if my solution could help you since the setting is different, but you can have a try.

Here is the way I solve this issue:

Step1: install pythonw (I use the command "conda install python.app", but I am sure Enthought must use different command)

Step2: Launch .py file with pythonw instead python.

Hope it helps.

Graniela answered 11/11, 2016 at 23:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.