简体   繁体   中英

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 (ie, 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

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM