I tried upgrading Python 2.7 to Python 3 and modified the ~/.bash_aliases
file, but when I type python
in the elementary terminal, I get this error:
zsh: command not found: python3
Additionally, when I type which python
, I see:
python: aliased to python3
I would prefer to revert to Python 2.7, or if anyone knows how to fix this, I’d appreciate the help.
Revert the Alias to Python 2.7
Oh, this is something I’ve dealt with before, and it’s pretty straightforward! If you need to switch back to Python 2.7, you can tweak your aliases to make it happen. Head over to your ~/.bash_aliases
file and look for something like:
alias python=python3
Replace that with:
alias python=python2
Once done, save the file and run:
source ~/.bash_aliases
Now, when you type python
, it’ll default to Python 2.7. Simple, right?
Fix zsh Command Not Found for Python 3
Oh, Babita’s method works great, but let me add to that. If you’re on zsh
and encountering issues with Python 3 not being found, it might not be installed correctly. First, check if it’s installed by running:
which python3
If you don’t see a valid path, you’ll need to install Python 3:
sudo apt-get install python3
Once that’s sorted, you can update the alias to point to Python 3 instead of Python 2.7 by editing your ~/.bash_aliases
:
alias python=python3
And don’t forget to reload the configuration with:
source ~/.bash_aliases
Now, python
will point to Python 3, and the system should recognize python3
too.
Remove the Alias Temporarily to Use the Default Python Version
Babita and Charity covered the alias changes well! But if you’re in a situation where you just want to test things out without making permanent changes, here’s a quick trick. Temporarily remove the alias by running:
unalias python
After that, check the default Python version on your system:
python --version
This lets you see which version the system uses by default without any alias interference. If you’re happy with the result and want to stick to Python 3 (or revert to Python 2.7), you can always go back to updating your alias as Babita explained earlier.