I guess the Python kernel / environment in your Jupyter notebook might not be the same you are using in your terminal by running python script.py.
Could create a (new) conda environment and execute the notebook as well as run your script in this env?