Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wx can't run on mac

I installed anaconda instead of system's python on mac,but when I type

import wx
app = wx.App()

I got this:

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 use the script:

#!/bin/bash

# what real Python executable to use
PYVER=2.7
PYTHON=/Library/Frameworks/Python.framework/Versions/$PYVER/bin/python$PYVER

# find the root of the virtualenv, it should be the parent of the dir this script is in
ENV=`$PYTHON -c "import os; print os.path.abspath(os.path.join(os.path.dirname(\"$0\"), '..'))"`

# now run Python with the virtualenv set as Python's HOME
export PYTHONHOME=$ENV 
exec $PYTHON "$@"

but it just used the system python.Can't use the lib in anaconda. I want to use the wx GUI in anaconda,how to solve the problem?

like image 311
XiaXuehai Avatar asked Oct 12 '16 03:10

XiaXuehai


1 Answers

I fixed the issue for my Python 2 and 3 virtual envs by reading this post (see my tip in the followed):

  • https://blurringexistence.net/wxpython-using-virtualenvwrapper-on-osx.html

My environment is:

  • macOS 10.12.5
  • Python 2 installed by Homebrew
    • wxPython installed through: brew insstall wxpython
  • Python 3 installed by Homebrew
    • wxPython installed through: gpip3 install wxpython (the global PIP for Python 3)

Tips:

  • You could modify the script in that post to work for Python 3.
  • You should set "PYTHONHOME" in the "activate" file instead of "postactivate" if you DO NOT use virtualenvwrapper.
like image 53
Alan Zhiliang Feng Avatar answered Oct 09 '22 04:10

Alan Zhiliang Feng