I assume you are using a Jupyter notebook, which might not show the error message properly, but instead would kill the kernel and restart it.
Try to run the script in the terminal and check, if you would get a valid error message.