Bear in mind that variable labels are not necessarily valid as variable names even ignoring the space issue. They might also be duplicates, since labels don't have to be unique. And some variables might not have labels or some labels might conflict with existing variable names.
However, ignoring those issues, you can do the renaming like this.
begin program python.
import spssaux
vardict = spssaux.VariableDict("V1 to V3")
for v in vardict:
vlabel = v.VariableLabel.replace(" ", "_")
if vlabel:
spss.Submit(f"""RENAME VARIABLES ({v.VariableName} = {vlabel})""")
end program.
If you want to rename all labelled variables, just omit "V1 to V3" above.
------------------------------
Jon Peck
------------------------------