psychopy.org | Reference | Downloads | Github

NameError: name 'visual' is not defined

importing

#1

I’m new to both Python and Psychopy. I’m trying to get Psychopy to work with an external module, pydicom, that will allow me to import (and display) DICOM images (thanks to contributors Michael and mdc for helping with this aspect on a previous post).
I have installed pydicom (called as “dicom”) in a folder in my Documents directory on my Windows 7 computer. I have set the path to this directory in the preferences for Psychopy. The p[roblem is that loading the dicom module seems to block the psychopy functions. Here is the relevant code:

import psychopy
import numpy, dicom 

# list default parameters here
windowSize = [400, 400]
fixationSeconds = 0.5
stimulusSeconds = .5

# create window and stimuli
win = visual.Window(windowSize, allowGUI = True, monitor = 'testMonitor', units = 'deg')

At this point, running the code generates the following error:

############### Running: H:\Experiments\Programming\dicomTest.py ###############
Traceback (most recent call last):
  File "H:\Experiments\Programming\dicomTest.py", line 18, in <module>
    win = visual.Window(windowSize, allowGUI = True, monitor = 'testMonitor', units = 'deg')
NameError: name 'visual' is not defined

I have tried adding an extra “import psychopy” command after I import dicom, but that didn’t help.


#2

This is nothing to do with importing dicom. It’s just a plain bug in your code :wink:

name 'visual' is not defined is because you need to write

from psychopy import visual

if you want to use the visual module


#3

Aha! I thought import psychopy would do the trick.

thanks!