I installed the earlier version (3.11.2) normally using apt package manager and the later version (3.12) manually from source. When I execute python scripts like so:
./python_script.py The script uses the earlier version instead of the later one. I would like to leave the default shebang line #!/usr/bin/env python3 at the beginning of the script alone for portability reasons.
Here is a sample test script.
#!/usr/bin/env python3 import sys def main(): print(sys.version) main() EDIT: With the above configuration, I'm thinking at this point the quickest fix (probably not the best because of future consequences, please see well explained answers and comments from the community below) is to change the target of the python3 symlink in /etc/alternatives to /usr/local/bin/python3.12 where my python3.12 binary is stored.
EDIT2: As seen in the second screenshot, I was able to get ./myscript.py to use the python version I wanted (3.12) by verifying that the /usr/local/bin directory is before the /usr/bin directory in my PATH environment variable and renaming the python3.12 binary in /usr/local/bin/ to python3.


pyenv(github.com/pyenv/pyenv) for this. It makes it very easy to install and select different versions of python./usr/local/bincontaining my ownpython3.12built binary before/usr/binthe system default in thePATH(See picture above). As you can see, when I run ./myscript.py the interpreter still uses the3.11.2system version of python. I must be missing something :-/ ?python3.12topython3in the/usr/local/bindirectory (See second screenshot added above)