Stimuli coordinates are different when run from PsychoPy vs. tuning from code

Dear users,

I have a problem which I cannot solve for a long time.
I designed a simple experiment on iMac (4K, 21.5 inches, 2019) I am using macOS Big Sur.

In the experiment, a square is displayed in the middle of the screen. The “x” coordinate of the mouse position is changing the size of the square. When I run the procedure using *.psyexp file, everything is working as expected.

BUT I have to run this file using python using file saved in *.py. When I use the terminal to run the file with Python3.9 the procedure works, mouse starts in the position (0,0) as it should but the size of the square is completely disproportional to the position of the mouse (mouse starts in the centre so the square should not be visible).

It looks like this is a scaling problem. Does anyone know how to solve this? Is it a generic problem that the procedure does work in psyexp and not using *.py?

I tried running it with python 3.10 and 3.6 with the same outcome.

Thank you for your help