I want to completely replace python 3 with python 2 in arch linux. I have already read https://wiki.archlinux.org/index.php/Python but it only provides a temporary fix. I need to ensure that when I call
#!/usr/bin/python
My program is using python 2 instead of python 3.
Yes, you should be able to switch between python versions. As a standard, it is recommended to use the python3 command or python3. 7 to select a specific version. The py.exe launcher will automatically select the most recent version of Python you've installed.
You can try the command line tool update-alternatives . Change the path /usr/bin/python3 to your desired python version accordingly. python2 and python3 are not alternatives.
While Python 2.7 and Python 3 share many similar capabilities, they should not be thought of as entirely interchangeable. Though you can write good code and useful programs in either version, it is worth understanding that there will be some considerable differences in code syntax and handling.
In Arch, /usr/bin/python
is actually a symlink to python3. Assuming you've already installed python2, as root, change the symlink to point to python2:
cd /usr/bin
ls -l python
lrwxrwxrwx 1 root root 7 5 sept. 07:04 python -> python3
ln -sf python2 python
ls -l python
lrwxrwxrwx 1 root root 7 Dec 11 19:28 python -> python2
If you're using the python2-virtualenv
package, then do the same for /usr/bin/virtualenv
:
cd /usr/bin
ln -sf virtualenv2 virtualenv
Changing the default symlink is a bad idea, and it gets recreated on python3 updates. Instead, create a local python
override:
sudoedit /usr/local/bin/python
Paste this inside and save the file:
#!/bin/bash
exec python2 "$@"
Don't forget to make it executable:
sudo chmod +x /usr/local/bin/python
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With