ModuleNotFoundError: No module named 'psychopy'

Hi!
I have folder with file master.py, which runs digit_span.py from subfolder digit_span.
When I use Spyder, everything works fine. But when I try to run master.py with system Python, I got the error “ModuleNotFoundError: No module named ‘psychopy’”. Curiosly if I call digit_span.py directly via console with system Python, it runs perfectly. I installed psychopy to my system Python, as well as to conda new environment. So I think that the problem hides somewhere in my master.py.

master.py:

if __name__ == "__main__":
    import os
    import subprocess
    cDir = os.path.dirname(os.path.realpath(__file__)) + "/digit_span" 
    subprocess.call(["python", "digit_span.py"], cwd=cDir)

I need to call script via console because I won’t be able to install Anaconda to experimental laptop.

System: macOS Catalina v. 10.15.7
Spyder 3.3.6 Python 3.6.13 64-bit | Qt 5.12.9 | PyQt5 5.12.3 | Darwin 19.6.0
System Python 3.8

I would very appreciate any help!

That’s definitely a little odd. I think it’s an issue with how subprocess works, where it’s calling the wrong version of Python somehow. Macs like to keep a version of Python 2.7 buried somewhere even if you’ve updated the system Python to 3.x. As a step 1, I would try the following:

    subprocess.call(["python3", "digit_span.py"], cwd=cDir)

However, since every version of Python you are using is 3.6 or later, you may want to use a different function (see documentation of “subprocess.run” here).

    subprocess.run(["python3", "digit_span.py"], cwd=cDir)

Functionally this should be basically identical but as you can see from the documentation there are more options available to diagnose exactly what’s going on.

This post feels relevant (for someone who knows nothing about Spyder and Anaconda).

Thank you very very much, now it works from console!
But unfortunately now here comes another issue: both files (master.py as well as psychopy script digit_span.py) run, but immediately terminate with error “unexpected python termination”.

digit_span.py finishes with error “Illegal instruction: 4”. I suppose the error is the same for both scripts (because, let me remind you, master.py calls digit_span.py).

Recently, just few hours ago, experimental scripts ran very well! I attached a video that illustrates how everything goes wrong((

And the error (sorry, its on Russian, but I hope it would be clear)

Something like has happened before, but I’m not sure it’s the same thing:

You might want to check the version of PsychoPy being used by the system python when you call python3. Try running this in terminal:

pip3 show psychopy

However the underlying issue is one that I don’t think we’ve ever identified. It’s probably related to PyQt somehow, but it’s hard to say how.

Thank you for your answer, it’s very kind of you!