BASH Script: Tame Python 2 / Python 3 version conflicts on Linux systems – hackish, but works!

WARNING: This is not the right way, nor the best way, of working with different python versions on the same system! virtualenv is the correct tool for the job, no doubt. Before running this hackish script you must make certain that the paths match your system’s particular Python installation paths!

That being said, if you run a system that uses Python 2.x for most things and you just need to occasionally run a Python 3.x application, for example, this is a quick and dirty hack to help out! It is by no means a method which should be packaged with any apps you plan to distribute, or anything that will see something remotely resembling a ‘production’ environment. This is just a hack to use if you need to quickly switch back/forth between Python versions in a system wide manner!

The example below was designed to work on an Arch Linux system, where most everything uses Python 2, but in which I have installed a couple of programs from the AUR (Arch User Repository) which require Python 3. Even if you run Arch Linux DO NOT ASSUME THIS WILL JUST WORK FOR YOU! Check the paths and make sure! Arch is a very dynamic distro, and these things could change tomorrow for all I know! This is a highly hackish solution, and if you fubar your python installation because you didn’t check these file locations on your particular system, don’t blame me! :P Warnings aside, I have tried my best to put some checks in place to make sure it isn’t too dangerous, but I am no bash scripting guru, just a guy sharing a hack – so your mileage may very!

Just put this in a file named Then run ‘chmod +x’ on it, to make it executable. And to be safe, first run it without any parameters to see a usage example and to verify the config variables. So long as you run it with no parameters it will attempt no changes to your system!

Leave a Reply