I'm running AIX 7.3 and I have several Python versions installed, ranging from 2.7 to 3.9. Despite my efforts, it seems like 2.7 is always selected as the default version, and my scripts won't recognize the shebang line for Python 3. I think I have to keep 2.7 since Aaas requires it, so uninstalling it isn't an option. Has anyone dealt with this issue before and can offer some troubleshooting tips?
2 Answers
I’m not too familiar with AIX, but on Windows, the order of system variables is crucial in selecting the default Python version. Maybe you could try reordering the system variables to put Python 3.x first. Also, test if you can run a script directly by calling the binary, like `/path/to/python3.9 script.py`, to see if that works.
It looks like you're having trouble with the shebang not being honored on AIX. AIX isn't based on Bash, so it might not respect the shebang line. To explicitly call a specific Python version, try executing your script using the binary directly, like `executable script_name.py`. A virtual environment would be best to manage different versions; you can run it as `.venv/bin/python myfile.py` to ensure you're using the right interpreter.
Just to clarify, the shebang is actually read by the kernel, not the shell, so that's not the issue. If `/bin/python3` is actually pointing to Python 2.7, something might have gone wrong during installation. Check your setup! Also, using [pyenv](https://github.com/pyenv/pyenv?tab=readme-ov-file#linuxunix) can be a good solution. It allows you to manage multiple Python versions from your home directory, and you can use a shebang of `#!/usr/bin/env python3`.