| Reference | Downloads | Github

ImportError: cannot import name WeakMethod

When I try to run the following code:

myDlg = gui.Dlg(title="JWP's experiment")
myDlg.addText('Subject info')
myDlg.addField('Age:', 21)
myDlg.addText('Experiment Info')
myDlg.addField('Grating Ori:',45)
myDlg.addField('Group:', choices=["Test", "Control"])
ok_data =  # show dialog and wait for OK or Cancel

if myDlg.OK:  # or if ok_data is not None
    print('user cancelled')

I got the error:

ImportError: cannot import name WeakMethod

I tried to figure out a solution, and ended up downloading the latest version of Django with the command:

pip install Django==3.0.5

I am still getting the same error.

I use Ubuntu 18.04.3 LTS and Python 3.7.7

I have just realized that the line from psychopy import gui is triggering alone the error ImportError: cannot import name WeakMethod after I commented out the code above.

Hi @Kathia, the recommendations for installing PsychoPy on Linux machines are here, so would recommend you follow these steps rather than installing Django. That error has been reported before with Django, but refers to running Django from an unsupported version of Python. Try adding the following to your code, and check that the version of Python that is running your task is supported by your version of Django here:

import sys