Open9

PsychoPy 環境構築

snishiyamasnishiyama

Windowsの場合

pip install psychopy

で問題なく最新版のpsychopyをインストールできた

snishiyamasnishiyama

M1 Mac の場合

ERROR:: Could not find a local HDF5 installation.
         You may need to explicitly state where your local HDF5 headers and
         library can be found by setting the ``HDF5_DIR`` environment
         variable or by using the ``--hdf5`` command-line option.

というエラーが見られたので,

homebrew で hdf5をインストール

brew install hdf5
snishiyamasnishiyama

.zshrc に以下を追加すると,上記のエラーは見られなくなった。

echo 'export HDF5_DIR="/opt/homebrew/opt/hdf5"' >> ~/.zshrc
snishiyamasnishiyama

が,次は psychtoolbox のインストール中に以下のエラーが発生

Collecting psychtoolbox
  Downloading psychtoolbox-3.0.18.2.zip (2.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.9/2.9 MB 17.8 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/kv/85z30cr9443bg0hyn2xx594r0000gn/T/pip-install-elmu1alh/psychtoolbox_7227841a92b3455594153e7304f0105b/setup.py", line 11, in <module>
          import numpy                                # To get include dir on macOS.
      ModuleNotFoundError: No module named 'numpy'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

numpy は psychtoolbox よりもインストールされているので,このエラーはよくわからない

snishiyamasnishiyama

先にpip install numpy をしたら,上記の問題は発生しなくなった

snishiyamasnishiyama

以下,それぞれエラーが発生したので,手間をかけた依存パッケージ

pyqt5 のインストール

pip install pyqt5だとうまく行かないので,ズルをする

brew install pyqt@5

シンボリックリンクを作る

ln -s /opt/homebrew/Cellar/pyqt@5/5.15.7_1/lib/python3.9/site-packages/* ./.venv/lib/python3.9/site-packages
ln -s /opt/homebrew/Cellar/pyqt@5/5.15.7_1/lib/python3.9/site-packages/* ~/.pyenv/versions/3.9.13/lib/python3.9/site-packages

pyo のインストール

brew install portaudio libsndfile portmidi
export LDFLAGS=-L"$(brew --prefix)/lib"
export CFLAGS="-I/$(brew --prefix)/include"
export CXXFLAGS="-I/$(brew --prefix)/include"
pip install pyo

wxpython のインストール

pip install wxpythonだとうまく行かないので,ズルをする

brew install wxpython

シンボリックリンクを作る

ln -s /opt/homebrew/Cellar/wxpython/4.1.1_2/lib/python3.9/site-packages/* ./.venv/lib/python3.9/site-packages   
ln -s /opt/homebrew/Cellar/wxpython/4.1.1_2/lib/python3.9/site-packages/* ~/.pyenv/versions/3.9.13/lib/python3.9/site-packages 

psytoolbox

git clone https://github.com/Psychtoolbox-3/Psychtoolbox-3.git
cd Psychtoolbox-3
python setup.py install

以下を参考

https://github.com/waltervanheuven/psychopy-on-M1/blob/main/v2022.2.2 Qt6.md#9-install-psychtoolbox-from-source

psychopy

pip install psychopy

でうまくいった

以上 M1 mac でのpsychopy パッケージのインストール。homebrewで pyqt5 や wxpython をインストールしたために homebrew の環境(?)が結構ぐちゃぐちゃ感がある

snishiyamasnishiyama

動作確認

win/M1 mac のいずれでも以下のコードで動作確認。もっと色々なパッケージをを使った場合の挙動は不明

from psychopy import core, visual

win = visual.Window()

text = visual.TextStim(win)
text.draw()
win.flip()

core.wait(3)

win.close()
core.quit()
snishiyamasnishiyama

結論

psychopy を使うなら,Windows PC を使うのが楽!ここでは取り上げていないが,intel macもそれほど大変ではなかったはず(過去に取り組んだ)。