No import psychopy

I don’t understand something. If I use builder to make a simple textbox, it runs but no screen appears. On inspection, there is no “import pyschopy” that happens before “from psychopy import locale_setup”.

I am on python3.9.The way pkgs are imported has changed. Perhaps it is no longer required. However, the Experiment Runner still says:
from psychopy import locale_setup
ModuleNotFoundError: No module named ‘psychopy’

Here is the beginnings of the myexperiment.py file that is run.

from future import absolute_import, division

from psychopy import locale_setup
from psychopy import prefs
from psychopy import sound, gui, visual, core, data, event, logging, clock
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)

import numpy as np # whole numpy lib is available, prepend ‘np.’
from numpy import (sin, cos, tan, log, log10, pi, average,
sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os # handy system and path functions
import sys # to get file system encoding

from psychopy.hardware import keyboard
:
My question is: Why is the builder generated myexperiment.py file not including the import psychopy?

OS (e.g. Win10): mac sierra
custom build
python3.9

That’s just how Python importing works (I’d be surprised if it changed that much in 3.9). If you only need certain sub-modules then you typically just import those. Builder scripts don’t need to use the name psychopy, they only need its subpackages, like visual, core, etc.

Before python3.9, you have to import before you can use the modules.

Pkg changes in 3.9:
http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html

What i don’t understand is why builder won’t include the “import psychopy” but then complain about it not being there? And to fix this quickly, can i add that import pyschopy before the from psychopy import locale_setup?

I don’t see anything in that doc that relates to version 3.9. The current builder scripts certainly work fine in version 3.6 (which is what we package) and v3.8 which is quite widely used too. I also don’t see anything about the need for import psychopy

In the error message that you’re reading:
ModuleNotFoundError: No module named ‘psychopy’
that message is coming from Python itself, not a message from Builder. But it doesn’t indicate an incorrect import method, it indicates that the psychopy package has not been installed on this Python installation. I expect you’ve got more than one python installation on your computer, one with psychopy installed and one without, and you’re trying to run a psychopy script from the wrong one.

If you just do import psychopy you’ll still get that error message.

If you try adding

import sys
print(sys.executable)

that will tell you what Python exiecutable you’re using and then you can check whether that one has a psychopy lib in its packages

Something has misaligned after my upgrade to python3.9
The experiment runner, which is at python 3.9.4 has no problem importing pyschopy.

But if i run it from
Screen Shot 2021-06-28 at 12.32.05 PM

I get:
from psychopy import locale_setup
ModuleNotFoundError: No module named ‘psychopy’

Slightly tangential but related:

(2) python3.9 can clearly import psychopy
Python 3.9.4 (default, Jun 24 2021, 20:24:08)
[Clang 8.1.0 (clang-802.0.42)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

import psychopy

(3) pip3.9 doesn’t think it has psychopy
pip3.9 show psychopy
WARNING: Package(s) not found: psychopy

(4) When I attempt to get pip3.9 to install psychopy, it runs into errors. I am not sure what to do yet about this.
The conflict is caused by:
psychopy 2021.2.0 depends on tables
:

For now, the problem is temporarily shelved by rolling back to a older version of python.