How do I get PsychoPy working in PyCharm on mac?

I feel very stupid but I can’t get PyCharm to run a PsychoPy script for anything, and every time I try to load the interpreter in PyCharm it throws a fit.

I know the correct interpreter (/Applications/PsychoPy2.app/Contents/MacOS/python), but anytime I try to do anything with it I get:

from psychopy import visual, event, core, data, gui, monitors, tools, sound File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psychopy/__init__.py", line 43, in <module> from psychopy.preferences import prefs File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psychopy/preferences/__init__.py", line 13, in <module> from . import preferences as prefsLib File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psychopy/preferences/preferences.py", line 6, in <module> from builtins import object File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/builtins/__init__.py", line 8, in <module> from future.builtins import * File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/future/builtins/__init__.py", line 10, in <module> from future.builtins.iterators import (filter, map, zip) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/future/builtins/iterators.py", line 38, in <module> from future import utils File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/future/utils/__init__.py", line 54, in <module> import copy File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 52, in <module> import weakref File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 14, in <module> from _weakref import ( ImportError: cannot import name _remove_dead_weakref
This also occurs if I try to get it to “Install packaging tools”, which it wants to do when you select the thing.

I also can’t install PsychoPy as a package into its default python environment, which would seem to be the logical alternative. It gives me an error message about needing to run with sudo -H, which I can’t do from PyCharm. PyCharm’s documentation is also grossly inadequate.

@jon I know you use PyCharm, what am I missing?

I use pycharm with a standard python install. When I use standalone PsychoPy I just use the Coder.
There’s something about the packaging of the python inside the app that means it doesn’t like being launched like a regular python. It knows that it has been “frozen” somehow

As Jon mentioned, the download from the PsychoPy website will be difficult to get working with Pycharm. Instead, create a virtual environment, and use pip to download PsychoPy and run your script in Pycharm with that environment.

FWIW I use PyCharm and Psychopy with Anaconda Python and that also works well.

I tried to get the /Applications/PsychoPy2.app/Contents/MacOS/python version to work with Pycharm, figuring that maybe I could make the interpreter happy by setting its environment variables from PyCharm before launching the Python interpreter, but finally gave up after dorking with that for a while and failing to make it work. The availability of working alternatives discourages significant expenditure of effort on that.

-Allen

Thanks all. I tried getting PsychoPy using PyCharm’s package installer and it got it, and when I hit run it launches a python something but doesn’t actually successfully load a window or anything. That doesn’t seem to be an issue of it missing psychopy, just something about the whole python setup. For now, I have a workflow that is adequate (edit in PyCharm, test in PsychoPy).

This would be fixed by a rethink of how we package/deliver the Standalone. I’m thinking about re-working that to be a network-install script rather than providing all the packages in a single download:

As this thread was from 2018, I wanted to check if this is still the case that it’s not possible to point PyCharm to use the interpreter installed by the standalone install?

Hi there,

I just made it work on a MacBook Pro (Apple M1, Ventura 13.5.2 and PyCharm 23.2.1, Community Edition). However, the solution involved the Anaconda platform (https://www.anaconda.com) as I could not find a way to use the standalone. I installed Anaconda first from the website. I created an environment using Python 3.8.18 and installed PyCharm via Anaconda. Installing the available version of PsychoPy with Anaconda (i.e., 2022.2.5) failed, but installing 2023.2.2 with pip via Anaconda ultimately worked. However, I first got an error with the package tables, but installing version 3.8.0 of tables via Anaconda before running pip install psychopy solved the problem. Finally, I created a PyCharm project and selected the conda environment as interpreter. Most of PsychoPy works with some exception (e.g., psychtoolbox), but this is a huge upgrade to my workflow.

Here are the steps in succession:

(1) Install anaconda

(2) Create environment with Python 3.8.18

(3) Install package tables (3.8.0) via Anaconda

(4) Install PsychoPy 2023.2.2 via pip to the environment created in (2).

(5) Create PyCharm project and select conda environment.

Hope that helps!

It is a pity that using PsychoPy with PyCharm is such a nuisance on macOS. On Windows, you can simply use the interpreter of the PsychoPy standalone in PyCharm…

Best,

Malte

1 Like