# Error running Psychopy from code on Mac on venv Python (needs framework python)

**URL:** <https://discourse.psychopy.org/t/error-running-psychopy-from-code-on-mac-on-venv-python-needs-framework-python/24433>\
**Category:** Development\
**Created:** [August 6, 2021, 10:56am UTC](https://discourse.psychopy.org/t/error-running-psychopy-from-code-on-mac-on-venv-python-needs-framework-python/24433 "2021-08-06T10:56:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonasanso](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonasanso/32/30617_2.png) [@jonasanso](https://discourse.psychopy.org/u/jonasanso)\
**Post date:** [August 6, 2021, 10:56am UTC](https://discourse.psychopy.org/t/error-running-psychopy-from-code-on-mac-on-venv-python-needs-framework-python/24433/1 "2021-08-06T10:56:26Z")

</div>

Hello,

I have cloned the repo and tried to run it from source on a Mac Big Sur without sucess.

I have read the troubleshooting pages and searched for similar errors and recommendations online, but I did not find a solution to my problem.

I followed the same process on a Mac Catalina with the same result.

I can confirm the standalone version works on Big Sur. I have installed psychopy using brew and had no problems with it.

But I am unable to run psycopy from code.

I set up python version and install the dependencies as follows

```auto
pyenv global 3.6.8
pyenv exec python -m venv env
source env/bin/activate
python --version
pip install --upgrade pip
python -m pip install -e .

```

When I run the app using

```auto
python psychopy/app/psychopyApp.py

```

I get this error without any splash screen or anything

```auto
(venv) psychopy [release●] % python psychopy/app/psychopyApp.py
pygame 2.0.1 (SDL 2.0.14, Python 3.6.8)
Hello from the pygame community. https://www.pygame.org/contribute.html
PTB-INFO: Using modified PortAudio V19.6.0-devel, revision unknown
2021-08-06 12:03:46.927 python[12933:3206575] -[NSApplication transformToForegroundApplication]: unrecognized selector sent to instance 0x7fad2dcc8560
2021-08-06 12:03:46.930 python[12933:3206575] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication transformToForegroundApplication]: unrecognized selector sent to instance 0x7fad2dcc8560'
*** First throw call stack:
(
	0 CoreFoundation 0x00007fff2067787b __exceptionPreprocess + 242
	1 libobjc.A.dylib 0x00007fff203afd92 objc_exception_throw + 48
	2 CoreFoundation 0x00007fff206fa38d -[NSObject(NSObject) __retain_OA] + 0
	3 CoreFoundation 0x00007fff205df90b ___forwarding___ + 1448
	4 CoreFoundation 0x00007fff205df2d8 _CF_forwarding_prep_0 + 120
	5 libwx_osx_cocoau_core-3.1.5.0.0.dyl 0x00000001097a2e5e _ZN5wxApp9DoInitGuiEv + 254
	6 libwx_osx_cocoau_core-3.1.5.0.0.dyl 0x00000001097f0d7e _ZN5wxApp9OnInitGuiEv + 30
	7 _core.cpython-36m-darwin.so 0x0000000108cb1a52 _ZN10sipwxPyApp9OnInitGuiEv + 98
	8 libwx_osx_cocoau_core-3.1.5.0.0.dyl 0x00000001097f0ba5 _ZN5wxApp10InitializeERiPPw + 165
	9 libwx_baseu-3.1.5.0.0.dylib 0x0000000109fce58b _Z12wxEntryStartRiPPw + 171
	10 _core.cpython-36m-darwin.so 0x0000000108cb11a3 _ZN7wxPyApp13_BootstrapAppEv + 499
	11 _core.cpython-36m-darwin.so 0x0000000108cb53f4 _ZL26meth_wxPyApp__BootstrapAppP7_objectS0_ + 100
	12 python 0x00000001028f5726 _PyCFunction_FastCallDict + 166
	13 python 0x0000000102981181 call_function + 497
	14 python 0x000000010297dff7 _PyEval_EvalFrameDefault + 25271
	15 python 0x0000000102981cec _PyEval_EvalCodeWithName + 2732
	16 python 0x00000001029824ca fast_function + 362
	17 python 0x000000010298115a call_function + 458
	18 python 0x000000010297dff7 _PyEval_EvalFrameDefault + 25271
	19 python 0x0000000102981cec _PyEval_EvalCodeWithName + 2732
	20 python 0x0000000102982887 _PyFunction_FastCallDict + 567
	21 python 0x00000001028a8f57 _PyObject_FastCallDict + 167
	22 python 0x00000001028a90e3 _PyObject_Call_Prepend + 131
	23 python 0x00000001028a8da5 PyObject_Call + 101
	24 python 0x000000010290dfed slot_tp_init + 157
	25 python 0x000000010290a184 type_call + 292
	26 python 0x00000001028a8ff2 _PyObject_FastCallDict + 322
	27 python 0x00000001028a93d5 _PyObject_FastCallKeywords + 197
	28 python 0x000000010298114a call_function + 442
	29 python 0x000000010297e094 _PyEval_EvalFrameDefault + 25428
	30 python 0x0000000102982569 fast_function + 521
	31 python 0x000000010298115a call_function + 458
	32 python 0x000000010297dff7 _PyEval_EvalFrameDefault + 25271
	33 python 0x0000000102982569 fast_function + 521
	34 python 0x000000010298115a call_function + 458
	35 python 0x000000010297dff7 _PyEval_EvalFrameDefault + 25271
	36 python 0x0000000102981cec _PyEval_EvalCodeWithName + 2732
	37 python 0x0000000102977cb0 PyEval_EvalCode + 48
	38 python 0x00000001029af9ee PyRun_FileExFlags + 174
	39 python 0x00000001029aefe4 PyRun_SimpleFileExFlags + 276
	40 python 0x00000001029cb121 Py_Main + 3249
	41 python 0x000000010289da21 main + 257
	42 libdyld.dylib 0x00007fff2051ff5d start + 1
)
libc++abi: terminating with uncaught exception of type NSException
[1] 12933 abort python psychopy/app/psychopyApp.py

```

**Thanks in advance to anyone reading this**

---

<div class="post-metadata">

**Author:** ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)\
**Post date:** [August 6, 2021, 11:50am UTC](https://discourse.psychopy.org/t/error-running-psychopy-from-code-on-mac-on-venv-python-needs-framework-python/24433/2 "2021-08-06T11:50:46Z")

</div>

Could you tell me what Python installation you’re using (e.g. [python.org](http://python.org), conda or system python)? Also, is there any clue what happened if you do  
`cat ~/.psychopy3/last_app_load.log`

---

<div class="post-metadata">

**Author:** ![jonasanso](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonasanso/32/30617_2.png) [@jonasanso](https://discourse.psychopy.org/u/jonasanso)\
**Post date:** [August 6, 2021, 3:15pm UTC](https://discourse.psychopy.org/t/error-running-psychopy-from-code-on-mac-on-venv-python-needs-framework-python/24433/3 "2021-08-06T15:15:58Z")

</div>

Thanks @jon

I am using the python version installed via pyenv 3.6.8

```auto
(env) psychopy [release●●] % pyenv versions
  system
* 3.6.8 (set by /Users/jonaspro/.pyenv/version)

```

So I believe it is not system python and not conda.

When I check the file it exists but it is empty

```auto
(env) psychopy [release●●] % cat ~/.psychopy3/last_app_load.log
(env) psychopy [release●●] %

```

Any idea what could be going on?

---

<div class="post-metadata">

**Author:** ![jonasanso](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonasanso/32/30617_2.png) [@jonasanso](https://discourse.psychopy.org/u/jonasanso)\
**Post date:** [August 6, 2021, 3:33pm UTC](https://discourse.psychopy.org/t/error-running-psychopy-from-code-on-mac-on-venv-python-needs-framework-python/24433/4 "2021-08-06T15:33:05Z")

</div>

I can try any python version or any way to install python and the requirements.

---

<div class="post-metadata">

**Author:** ![jonasanso](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonasanso/32/30617_2.png) [@jonasanso](https://discourse.psychopy.org/u/jonasanso)\
**Post date:** [August 9, 2021, 7:52am UTC](https://discourse.psychopy.org/t/error-running-psychopy-from-code-on-mac-on-venv-python-needs-framework-python/24433/5 "2021-08-09T07:52:57Z")

</div>

I have debugged the code and I see it crashing [here](https://github.com/psychopy/psychopy/blob/40e0e216bd692b0e3c8d02f78c6d88fe968063e9/psychopy/app/_psychopyApp.py#L214)

```auto
 wx.App. __init__ (self, arg)

```

The internal code inside wx executes until we get to the end of the ` __init__ ` function where it does

```auto
        # This finishes the initialization of wxWindows and then calls
        # the OnInit that should be present in the derived class
        self._BootstrapApp()

```

After that I see the error that I mentioned and `onInit` is never called

Details on wx version

```auto
(env) psychopy [release] % pip show wxPython                
Name: wxPython
Version: 4.1.1
Summary: Cross platform GUI toolkit for Python, "Phoenix" version
Home-page: http://wxPython.org/
Author: Robin Dunn
Author-email: robin@alldunn.com
License: wxWindows Library License (https://opensource.org/licenses/wxwindows.php)
Location: ./psychopy/env/lib/python3.6/site-packages
Requires: numpy, pillow, six
Required-by: PsychoPy

```

---

<div class="post-metadata">

**Author:** ![jonasanso](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonasanso/32/30617_2.png) [@jonasanso](https://discourse.psychopy.org/u/jonasanso)\
**Post date:** [August 9, 2021, 12:22pm UTC](https://discourse.psychopy.org/t/error-running-psychopy-from-code-on-mac-on-venv-python-needs-framework-python/24433/6 "2021-08-09T12:22:11Z")

</div>

Solution to my problem.

Install python enabling framework and then do the rest of the installation as defined

```auto
PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.6.8

```

The issue was with wx and the need for a framework

When running a simple ws app

```auto
import wx

app = wx.App(False) # Create a new app, don't redirect stdout/stderr to a window.
frame = wx.Frame(None, wx.ID_ANY, "Hello World") # A Frame is a top-level window.
frame.Show(True) # Show the frame.
app.MainLoop()

```

I got this error

```auto
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.

```

That lead me to this wiki [wxPythonVirtualenvOnMac - wxPyWiki](https://wiki.wxpython.org/wxPythonVirtualenvOnMac) and other stackoverflow pages indicating

```nohighlight
If you are getting the error that "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." 

The reason is because some 3rd party tools like PyInstaller might require CPython installation be built with --enable-framework. 

What you need to do is run $ env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.x.x in your terminal.

```

---

<div class="post-metadata">

**Author:** ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)\
**Post date:** [August 9, 2021, 5:14pm UTC](https://discourse.psychopy.org/t/error-running-psychopy-from-code-on-mac-on-venv-python-needs-framework-python/24433/7 "2021-08-09T17:14:47Z")

</div>

Well done for working that out. I personally use the [python.org](http://python.org) installation, which is indeed a “framework” installation. Glad there’s a way for it to work with venv python as well
