import keyboard
print('Press space twice to replay keyboard actions.')
keyboard.play(keyboard.record('space, space'), 3)

# -*- coding: utf-8 -*-
import keyboard
print('Press space twice to replay keyboard actions.')
keyboard.play(keyboard.record('space, space'), 3)

Add encoding definition to __main__ as preventive measure