# Fatal Python error: PyImport_GetModuleDict: no module dictionary! when creating MovieStim3 object

#1

Hi Psychopy Community,

Repost from earlier thread as some things have changed and I want to make sure this error and any solution is easy for others to find. I’m trying to create a MovieStim3 object, I’m getting an error that I’m not sure how to resolve, although now I’m not sure if I need to worry about it. Any help would be greatly appreciated!

Potentially useful information about my setup:

• Using psychopy standalone version 1.90.2, python 3
• Running on Windows 10 laptop
• Dual monitor setup, second monitor UHD

The Problem:
When I try to create a MovieStim3 object. I get a “Fatal Python error” message.

What has changed:
I’ve been trying different things to figure out what is going on, and in particular I tried to make a short run of two movies in Builder view. Surprisingly, it ran, but gave me the same error after the movies finished playing. What is going on here? Should I be worried about this “fatal error”?

I’m using moviepy as the backend in Builder (avbin did not play the movies at all and openCV did not properly sync sound and image and dropped many frames). The error seems to occur in a moviepy deconstructor.

Minimal (Non)Working Example:

import psychopy
psychopy.useVersion('latest')

from psychopy import monitors, visual, core

expMonitor = monitors.Monitor('subjectMonitor')
SCREEN_SIZE = (3840,2160)

window2use = visual.Window(
SCREEN_SIZE, fullscr=True, screen=1,
monitor=expMonitor, color=[0,0,0], colorSpace='rgb')

movieFullPath = r'C:\path\to\movies\testmovie.mp4'

thisMovie = visual.MovieStim3(win=window2use, name='testmovie',
noAudio = False, filename = movieFullPath)

window2use.close()
core.quit()


Errors and Warnings this code produces:

##### Running: C:\Users\Megan\Documents\socEvalTask\socialEvaluationTask\psychopyPilot\MWE.py #####
1.3457     WARNING     User requested fullscreen with size [3840 2160], but screen is actually [2560, 1440]. Using actual size
3.5714     WARNING     Couldn't measure a consistent frame rate.
- Is your graphics card set to sync to vertical blank?
- Are you running other processes on your computer?

3.8320     WARNING     t of last frame was 26.46ms (=1/37)
3.8653     WARNING     t of last frame was 27.20ms (=1/36)
3.8994     WARNING     t of last frame was 27.77ms (=1/36)
3.9322     WARNING     t of last frame was 25.60ms (=1/39)
3.9655     WARNING     Multiple dropped frames have occurred - I'll stop bothering you about them!
5.4655     WARNING     Couldn't measure a consistent frame rate.
- Is your graphics card set to sync to vertical blank?
- Are you running other processes on your computer?

5.4655     WARNING     FrameRate could not be supplied by psychopy; defaulting to 60.0
5.7489     INFO     Loaded SoundDevice with PortAudio V19.6.0-devel, revision 396fe4b6699ae929d3a685b3ef8a7e97396139a4
5.7490     INFO     sound is using audioLib: sounddevice
7.1327     EXP     Created testmovie = MovieStim3(__class__=<class 'psychopy.visual.movie3.MovieStim3'>, autoLog=True, color=UNKNOWN, colorSpace=UNKNOWN, depth=0.0, filename=str(...), flipHoriz=False, flipVert=False, fps=UNKNOWN, interpolate=True, loop=False, name='testmovie', noAudio=False, opacity=1.0, ori=0.0, pos=array([0., 0.]), size=array([1600., 1000.]), units='pix', vframe_callback=UNKNOWN, volume=UNKNOWN, win=Window(...))
7.1900     EXP     window1: mouseVisible = True
Fatal Python error: PyImport_GetModuleDict: no module dictionary!

Current thread 0x00001e6c (most recent call first):
File "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 116 in __del__


#2

Hi heuristicwondering,

Does the error cause your script to crash, or is it just more of a nuisance? If your program is running fine, perhaps this error can just be ignored.

One thing worth investigating is the actual workings of "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 116 in __del__
I know it’s not the best thing to do, but if the lack of the module dictionary is crashing your script, and if the dictionary isn’t actually necessary to run your program, you might consider commenting out the lines in the backend that go looking for the non-existent dictionary. I’ve seen similar tactics work well in the past.

Good luck!

#3

Hi ebd5,

Sorry for the delay in reply, been trying to figure out this error more. It wasn’t causing the script to crash, and wasn’t being triggered until the experiment ended. Now that I want the option of playing some movies twice, I am having problems with this script crashing.

I believe these two issues (the Fatal Python error of the original post and crashing with trying to play twice) are related and have to do with garbage clean up. In particular, take a look at this MWE. Does this crash for you?

import psychopy
psychopy.useVersion('latest')

from psychopy import monitors, visual, core

expMonitor = monitors.Monitor('subjectMonitor')
SCREEN_SIZE = (3840,2160)

window2use = visual.Window(
SCREEN_SIZE, fullscr=True, screen=1,
monitor=expMonitor, color=[0,0,0], colorSpace='rgb')

thisMovie = visual.MovieStim2(win=window2use, name='testmovie',
noAudio = False, filename = movieFullPath)

window2use.close()
core.quit()


This also crashes for me with the below error message and it again appears to be related to the calling of a deconstructor.

##### Running: C:\Users\Megan\Documents\socEvalTask\socialEvaluationTask\psychopyPilot\MWE.py #####
1.6675     WARNING     User requested fullscreen with size [3840 2160], but screen is actually [2560, 1440]. Using actual size
5.3206     WARNING     Couldn't measure a consistent frame rate.
- Is your graphics card set to sync to vertical blank?
- Are you running other processes on your computer?

5.3656     WARNING     Failed to set VLC plugins path. This is only important for MovieStim2 movies (the OpenCV backend)
5.7219     WARNING     t of last frame was 30.46ms (=1/32)
5.7515     WARNING     t of last frame was 29.66ms (=1/33)
5.7873     WARNING     t of last frame was 29.62ms (=1/33)
5.8180     WARNING     t of last frame was 30.73ms (=1/32)
5.8583     WARNING     Multiple dropped frames have occurred - I'll stop bothering you about them!
8.2846     WARNING     Couldn't measure a consistent frame rate.
- Is your graphics card set to sync to vertical blank?
- Are you running other processes on your computer?

8.2847     WARNING     FrameRate could not be supplied by psychopy; defaulting to 60.0
Traceback (most recent call last):
File "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\psychopy\visual\movie2.py", line 328, in loadMovie
File "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\psychopy\visual\movie2.py", line 790, in _unload
self._releaseeAudioStream()
File "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\psychopy\visual\movie2.py", line 409, in _releaseeAudioStream
self._vlc_instance.vlm_release()
File "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\vlc.py", line 1937, in vlm_release
return libvlc_vlm_release(self)
File "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\vlc.py", line 4880, in libvlc_vlm_release
return f(p_instance)
OSError: exception: access violation reading 0x00000028
Exception ignored in: <bound method MovieStim2.__del__ of <psychopy.visual.movie2.MovieStim2 object at 0x0F339DF0>>
Traceback (most recent call last):
File "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\psychopy\visual\movie2.py", line 804, in __del__
File "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\psychopy\visual\movie2.py", line 790, in _unload
File "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\psychopy\visual\movie2.py", line 409, in _releaseeAudioStream
File "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\vlc.py", line 1937, in vlm_release
File "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\vlc.py", line 4880, in libvlc_vlm_release
OSError: exception: access violation reading 0x00000028
[0c4b38e8] mmdevice audio output error: cannot initialize COM (error 0x80010106)
[0c4d5878] mmdevice audio output error: cannot initialize COM (error 0x80010106)


I wish I had more information to give you than that, but at the moment I’m still trying to figure out what’s going on.

~Meg

#4

Hi heuristicwondering,

I tweaked just two things, and then your code ran fine for me. Here’s what I changed:

1. commented out “psychopy.useVersion(‘latest’)” and just used my local version (1.83.04) because I don’t have the git installed to specify version via useVersion().

2. used MovieStim3 rather than 2 (was there a reason you reverted back to MovieStim2?? This could be the source of all your VLC warnings–I believe the backends are different for 2 and 3.)

You seem to be getting a lot of audio errors too-- just to check, is that working okay? Are you sure the crash when loading isn’t because of an IO error regarding the audio?

#5

The reason I was using MovieStim2 was because MovieStim3 was creating terrible lag on the video stream, although the audio seemed fine. I’m in the process of trying different encodings to see if this is an issue. (I’ll report back on what I find). What encodings are you using for this test?

#6

did you solve it? I also encounter the same problem

#7

Hi zoubochao,

Sorry for the late reply, just saw this message. I could never get MovieStim2 to work. MovieStim3 worked, but only when I ran it on our facilities stimuli presentation system which has top of the line graphics hardware. The laptop I was developing on has a decent AMD card, but even then it would still lag on the video.

I admittedly did not write the code in a way that was very thoughtful about the computational loads being placed on the hardware, although I was still surprised that was the fix.

Have you made any progress with yours? Have you been able to test your code on different machines?

#8

Hi heuristicwondering,

I set the noAudio = True, and moviestim2 works now. my particular experiment can live without audio… this is not a solution…