Is it possible to use a shebang to force a certain Python 3 version? (ex python3.12 instead of python3)

1 week ago 8
ARTICLE AD BOX

I recently came back to a game I have been making, but I came back to a bunch of library errors and the such. I hadn't coded on Windows in a minute, and pygame.mixer didn't seem to work with the most recent version of Python (3.14) so I ended up installing python 3.12 which pygame does seem to work with. I've been working on and (usually) off for a few years now, and everytime I come back to it I feel like some import no longer has support on the current python version or some import hasn't been updated to the current version of Python yet.

In any case, I decided to stick with Python 3.12 for the remainder of this project, but I realized I don't know how to force 3.12 to be used when running the program. Sure, python 3.12 runs automatically on my system as it's the only Python installed, but I want python 3.12 to always be the installation ran on any device running my python script. Is there a way to make this happen, specifically for Windows and MacOS if not possible for all OS?

I know this forces python3 to be used, but I'm assuming it's specifically whatever the latest version of Python is, unless another Python3 version is already installed :

#!/usr/bin/env python3

Is there something to achieve something like this:

#!/usr/bin/env python3.12

I couldn't seem to find much information online about using shebangs for versions on python3 vs differentiating between python2/3, I'm mostly just curious if this is something that a shebang can be used for. I end up compiling my game through pyinstaller, into a Mac application or a .exe, and I haven't played around with how that works either. If I install it with Python 3.12, will the application be run with Python 3.12 even without a shebang line? Any help would be great, I honestly always came to Stack Overflow for some 7 year old answer to all my problems but I couldn't seem to find this one. I found this post from 2018 with no answer that was asking something similar, but thats about all.

Read Entire Article