I’ve been trying to switch between Python 3.7 and Python 3.8 on my Ubuntu system because I need to run some scripts that are version-specific. I read that using the `update-alternatives` method is the way to go, but honestly, I’m starting to feel a bit lost with it.
Here’s what I’ve done so far: I installed both versions using the package manager, so they’re both on my system. After that, I tried to configure `update-alternatives`. I created the first alternative for Python 3.7 using the command `sudo update-alternatives –install /usr/bin/python3 python3 /usr/bin/python3.7 1`. That seemed to work fine. Then I did the same for Python 3.8 with `sudo update-alternatives –install /usr/bin/python3 python3 /usr/bin/python3.8 2`.
After that, I ran `sudo update-alternatives –config python3` to choose between the two versions, and I was prompted to select what I wanted. I picked the option for Python 3.8 (I want to use that for a project), but when I check the version by running `python3 –version`, it still shows Python 3.7.
I also tried running `which python3` and it points to the same path, so it seems like it’s not updating correctly. I even restarted the terminal, but no luck. Has anyone else dealt with this? I’m kind of stuck here and could really use some advice on what I’m doing wrong.
I also made sure that there are no virtual environments messing up the paths. Is there something I might have missed in the `update-alternatives` setup? Should I be doing something specific to ensure that the switch is effective? Any tips or steps to double-check would be super helpful, as I’m really hoping to get this sorted out soon. Thanks in advance for any help you can give!
It sounds like you’re on the right track with using
update-alternatives
, but there might be a few things to check to make sure everything works smoothly.First off, since you already installed both versions and registered them with
update-alternatives
, that part’s good! But sometimes, the system might not pick up the changes immediately.Here are some steps to troubleshoot:
python3
:update-alternatives --display python3
This will show you the current priority and paths registered.
python3
might not point correctly. You can do this by running:ls -l /usr/bin/python3
This should show you if it’s pointing to
python3.8
orpython3.7
./usr/bin/python3.8 --version
This can help confirm that Python 3.8 is installed and working.
python3
command. Look for any lines likealias python3='...'
in your~/.bashrc
or~/.bash_profile
.If after all this it still doesn’t work, you can try resetting the alternative link:
sudo update-alternatives --config python3
And make sure to select Python 3.8 again.
Hope this helps you get it sorted out!
It sounds like you’ve made a solid start with using the `update-alternatives` method, and it can certainly be confusing at times. Since you’ve already set up the alternatives and chosen the version you want to use, the first step is to ensure that the symlink for `python3` is correctly pointing to the desired Python version. You can do this by checking the current symlink with the command
ls -l /usr/bin/python3
. Make sure that it points to the specific version you selected. If it still points to an older version, you can manually change it usingsudo ln -sf /usr/bin/python3.8 /usr/bin/python3
, which should override the default link.Additionally, if you’ve confirmed that the `update-alternatives` configuration seems correct and symlink update does not resolve the issue, it’s worth examining if there are any environment variables or shell configurations that are overriding it. Check your
~/.bashrc
or~/.bash_profile
files for any aliases that definepython3
. If you find any, you may want to modify or remove them. After making changes, don’t forget to source the file (e.g.,source ~/.bashrc
) or start a new terminal session. If problems persist, consider using a version management tool likepyenv
for switching between Python versions more seamlessly. This tool can simplify the management of multiple Python versions on your system significantly.