3

Running the sample hello-world code offered on wxpython-phoenix website throws a known error on osx. Hints at possible solutions can be found here, and here, but none seem to work with ipython and pycharm.

QUESTION: How to work around this known error, using ipython from within pycharm?

Set up:

OSX 10.12.5 Sierra
ipython 3.7.1 in a conda venv
pycharm CE 2018.3
(also fails from command line, and from jupyter notebook)

code ran: (from wxpython getting started page)

import wx
app = wx.App()
frm = wx.Frame(None, title="Hello World")
frm.Show()
app.MainLoop()

error message

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.

full traceback

---------------------------------------------------------------------------
SystemExit                                Traceback (most recent call last)
<ipython-input-1-5af94fb54276> in <module>
      3 
      4 # Next, create an application object.
----> 5 app = wx.App()
      6 
      7 # Then a frame.

~/anaconda3/envs/py37/lib/python3.7/site-packages/wx/core.py in __init__(self, redirect, filename, useBestVisual, clearSigInt)
   2100                 # TODO: more description is needed for wxMSW...
   2101 
-> 2102             raise SystemExit(msg)
   2103 
   2104         # This has to be done before OnInit

SystemExit: 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.

Note: This question is similar to:
- that one which was for python2.7, but did not receive an answer
- that one which offers outdated fixes for regular python, outside of pycharm
Other questions like this one, are obsolete for the new release of wxpython.

Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80

1 Answers1

2

When using conda environments you need to install the python.app package and then use pythonw to run applications that use wxPython.

On osx, the command line is: (as shown here)

conda install -c anaconda python.app

You will see the following message; confirm to proceed.

The following packages will be SUPERSEDED by a higher-priority channel:

    python.app: 2-py37_9 --> 2-py37_9 anaconda

With pycharm, it is necessary to change the project interpreter:

--> go to:

preferences
  project interpreter
    add interpreter
      conda environment
        anaconda (or anaconda3)
          bin
            pythonw 
select pythonw
apply
ok
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
RobinDunn
  • 6,116
  • 1
  • 15
  • 14