psychopy.org | Reference | Downloads | Github

ModuleNotFoundError: No module named 'psychopy' [Details Inside]

Hey, I’m new to Python and Psychopy but not really to programming. I’ve tried running the following:

print("foo")
from psychopy import visual, core, gui, event
print("bar")

Both from the command line and inside the Spyder IDE, I get the following error:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    from psychopy import visual, core, gui, event
ModuleNotFoundError: No module named 'psychopy'

System specs: macOS High Sierra v.10.13.4, Macbook Air

Python version: Python 3.7.1 (python -V)

I’ve installed the following dependencies: wxPython, pyo, and the ones in the following code:

pip install numpy scipy matplotlib pandas pyopengl pyglet pillow 
moviepy lxml openpyxl xlrd configobj pyyaml gevent greenlet 
msgpack-python psutil tables requests[security] pyosf cffi 
pysoundcard pysoundfile seaborn psychopy_ext python-bidi psychopy
pip install pyserial pyparallel egi iolabs
pip install pytest coverage sphinx

pip install pyobjc-core pyobjc-framework-Quartz

All from this resource. It seemed to run without a hitch (aside from some that didn’t like Spyder, but I ran it on the command line as well as Spyder, so that shouldn’t be a problem).

Any suggestions?

Inside your Python site packages directory, did those libraries all get installed there?

And is Spyder configured to use that version of Python, and not your system-provided Python?

Hi! I am having the same problem. I’m trying to import psychopy on spyder (not for the actual experiment but just to fiddle around with a few things). I keep pip installing it in the python console on spyder, however, whenever I try to import it in a script, it says:

ModuleNotFoundError: No module named ‘psychopy’

Btw. I also have psychopy downloaded normally to run the actual experiment etc. Does anyone know how to fix this?

Is the Python in your console the same one Spyder is set up to run scripts with?

Does the same thing happen when you pip install a non-PsychoPy package?

Dear Michael,

Thank you for your reply!

I would have thought it is, however, how would one check this? And unfortunately, it doesn’t happen when installing & importing modules other than psychopy. Is pip installing it in the python console & then importing it in a script a legitimate way to run psychopy in Spyder?

EDIT: I have tried creating a environment in anaconda using conda create & activated it, however, when I try to install psychopy in that environment, I get the following error.

ERROR: Command errored out with exit status 1:
     command: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/xw/lplw3cms2v78w_f7l8kbjv3m0000gn/T/pip-install-kd5wnd94/greenlet/setup.py'"'"'; __file__='"'"'/private/var/folders/xw/lplw3cms2v78w_f7l8kbjv3m0000gn/T/pip-install-kd5wnd94/greenlet/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/xw/lplw3cms2v78w_f7l8kbjv3m0000gn/T/pip-record-jdgoi765/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/greenlet
         cwd: /private/var/folders/xw/lplw3cms2v78w_f7l8kbjv3m0000gn/T/pip-install-kd5wnd94/greenlet/
    Complete output (9 lines):
    running install
    running build
    running build_ext
    building 'greenlet' extension
    creating build
    creating build/temp.macosx-10.9-x86_64-3.8
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c greenlet.c -o build/temp.macosx-10.9-x86_64-3.8/greenlet.o
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/xw/lplw3cms2v78w_f7l8kbjv3m0000gn/T/pip-install-kd5wnd94/greenlet/setup.py'"'"'; __file__='"'"'/private/var/folders/xw/lplw3cms2v78w_f7l8kbjv3m0000gn/T/pip-install-kd5wnd94/greenlet/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/xw/lplw3cms2v78w_f7l8kbjv3m0000gn/T/pip-record-jdgoi765/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/greenlet Check the logs for full command output.

I think you might need to install or update Apple’s command line tools required to build and install some packages. I used to think this required the massive Xcode install, but apparently not, e.g. see:

Thank you! In fact, I managed to get it to working in the end using advice from another post you replied to.

SOLUTION (if anyone else has this problem): Following installation of anaconda, I created an environment in the terminal.

conda create -n psychopyenv python=3.7

Then installed pip, spyder & psychopy in this environment.

conda install -n psychopyenv pip spyder psychopy

Then activated this environment & opened spyder within in.

conda activate psychopyenv
spyder

Then if you try to import or pip install psychopy & use modules within in on either the scripts or console, it works!

2 Likes