Don't use a named temporary file, and instead pipe its contents in with stdin
:
import tempfile, subprocess
installpip="echo 'hello'\n"
with tempfile.TemporaryFile() as scriptfile:
scriptfile.write(installpip)
scriptfile.flush()
scriptfile.seek(0)
subprocess.call(['/bin/bash', '-s'], stdin=scriptfile)
Of course this is not entirely bullet-proof either, but I'm sure you know that already.