You either have the first line in your Python script that looks like this:
#!/usr/bin/env python3
and the script marked executable in the Zsh shell:
chmod +x script.py
or you invoke your Python3 script in the following manner if the preceding she-bang is missing:
/usr/bin/python3 script.py

And any import clause, where the module is not part of the standard Python distribution would need to be installed beforehand.
In the case of your Python 3.9.6 (which I never use) that is what Apple still installs with the CommandLine Tools for Xcode, and I would not touch it with a stick. Instead, I download and use the current (3.13.3) package installer from Python.org. That is years more current than what Apple still provides, and it is installed into these locations:
- /Library/Frameworks/Python.framework
- /usr/local/bin
- Links to the relevant binaries in that preceding framework location
- e.g. python3, pip3, idle3, etc.
- /Applications
- Python 3.13 folder (I never run anything from here)
- IDLE
- Python Launcher
- other documents including ReadMe.rtf
Any third party packages that you install will be installed into that preceding framework location, and not in /Users/username/Library/Python/3.9/* where the Apple Python3 distributions are located.
When you install Python3 from Python.org, you will need to modify your Zsh shell PATH statement (e.g. .zshrc) to include the Python3 framework location:
export PATH=".:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
and with that PATH adjustment, Apple's Python 3.9.6 binaries and packages are seen after the Python.org installation and that is where the #!/usr/bin/env python3 invocation line comes into play. It will run the Python.org version and packages first as it should.