From what I understand, your Jupyter Notebook is using Java 1.8, while your standalone Python script is picking up JDK 17. This version mismatch is likely causing the issue, and it could also depend on the environment from which you are running Python.
If you set your JAVA_HOME to the Java 1.8 path (the same one Jupyter uses) and ensure your PATH points to that JDK, you should be able to initialize the VM successfully in your Python script. Make sure you are checking the correct environment when doing this.