What are the errors you see when running the script? @obtainhigh suggested installing the packages properly but I doubt that's the issue. You're code is poorly formatted but skimming through some parts I believe
sigdecode_string
doesn't seem to be extracting r and s correctly. Could you verify if it does?
If it doesn't, the calculation for the private key recovery will likely fail...