How to change python version ubuntu
How to change python version ubuntu
Installing Python 3.8.3 on Ubuntu 16.04, change the default version of python to the new version, and why is my terminal not working.
It was a long-winded process for me as a newbie when I tried to install python 3.8 on my computer. I am sharing my experience about what worked while installing, changing default versions and fixing the terminal that temporarily stopped working.
How to install Python 3.8 on Ubuntu 16.04?
Step 1: APT automates the retrieval, configuration and installation of software packages. Type these two commands in your terminal and hit enter each time.
Step 2: PPA (Personal Package Archive) are used to add a software to your Ubuntu. They cut down on time taken to install the software from the original source. PPA is an easy way to update a program via someone, in this case I am using deadsnakes PPA. Type the following command and hit enter.
Step 3: Once it is enabled, install Python 3.8 by typing the following command.
Step 4: Check the version by the following command. Your computer will display the new installed python version.
Python is installed. But wait! You are not done yet.
How to update default Python version on Ubuntu?
After installing new version of python 3.8, you will notice that if you type python in your terminal, it will still show you the old version of python. This means that you must make the following changes to allow the computer to be able to use new installed python version. Here are the steps that I took and they worked for me:
Step 1: To view the different versions on your computer:
Step 2: Copy the version you want. I my case, I copied /usr/bin/python3.8
Step3: Go to Home and type Shift+H to view hidden files
Step 5: Close the terminal and open it again. It is important to close the terminal to see the applied changes. Type the following command
Another way to update Python versions on Ubuntu.
This did not work for me. But might work for you.
Step 1: Install Python3.8. as mentioned above.
Step 2: Type the following commands. On the first line use your previous version(in my case its python3.5) and set the priority number to 1. On the second line use the new installed python version and set the priority to 2. According to Ubuntu
is an integer; options with higher numbers have higher priority in automatic mode.
How to fix the broken terminal?
So while changing the default version of python, I accidentally typed the wrong version numbers of python in the terminal and went ahead with the changes. Somehow this stopped the terminal and I was no longer able to open the terminal. I tried CTRL+ALT+T as well as restarting the computer but the terminal window did not open.
5. Select option 1.
6. At last type Ctrl+Alt+F7 to return to GUI
My terminal was up and running again.
If you find these guidelines useful, do let me know in the comments below. Have fun learning!
Change the Python3 default version in Ubuntu
9 Answers 9
From the comment:
Will show you an error:
Set python3.6 as default.
Or use the following command to set python3.6 as default:
if you have multiple version of python in your system. You just need to update the symbolic link of python inside /usr/bin/
Now update the python symlink using below command-
Using these commands can help you:
/.bashrc. Then you will make it work forever.
First check that you have a python3.6 folder?
If you have «python3.6» folder, you are good to go. Now update-alternatives
then update new config for python3
Finally, check default python3 version:
Create symlink for /usr/bin/python3. In my LinuxMint:
An easy answer would be to add an alias for python3.6.
Just add this line in the file
This solution fixes your problem without needing to tweak your system too heavily.
EDIT :
As Mikael Kjær pointed out, this is a misconfiguration of ansible with your system.
Set the ansible_python_interpreter configuration option to /usr/bin/python3. The ansible_python_interpreter configuration option is usually set per-host as an inventory variable associated with a host or group of hosts:
As seen here about the config file :
Changes can be made and used in a configuration file which will be processed in the following order:
On Ubuntu, how do you install a newer version of python and keep the older python version?
Given the background, how do you install a newer version of python and keep the older python version?
If I do the above commands, will the installation overwrite the old version of python I have (I definitely need the old version)?
4 Answers 4
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
I’m just going to assume that by «newer version» you mean «released version that is newer than the default version in Ubuntu». That means python 3.1, which is in the repositories.
Different python versions in the Ubuntu repositories can coexist with one another just fine. If you’re on a version of Ubuntu older than Lucid, you’ll have to upgrade your OS or enable the universe repository in order for python3 to show up in your package manager.
If you mean python 2.7, you should be aware that it hasn’t been released yet.
The Easy Way
To use a specific version of python (Ex. 2.4) just type python followed by the version number in the terminal:
To install libraries to a particular version of python just run setup.py the same way.
Ex. Install to python2.5
In this day and age, there’s really no need to build from source or worry about dependency tracking on most programs unless you’re developing it directly or you’re using a bleeding-edge non-stable branch.
If the newer stable revisions of python aren’t showing up in apt-get or synaptic, update your repository.
How to Change the Default Python Version to Python 3.9
John on December 17, 2020
After installing the latest version of Python 3 on your system, you will notice that an older version is still used when executing Python VIA the python and python3 commands.
In this article, we will learn how to change the default Python version so that it can be used without explicitly typing a version number.
Setting the Latest Python Version
If you have followed my article on how to install Python 3.9 on Ubuntu, you will notice that 3.9 is not the version used when running the following command:
To update Python to the latest version installed on your system, we can use update-alternatives to change the python shortcut command to point to Python 3.9.
You may also want to list Python 2.* versions if you want to add one of them as an option:
Now run the following commands changing the version numbers to suit what you have.
Now you can change the default version of Python using the following command:
Now check the default Python version has changed:
Conclusion
In this tutorial, you have learned how to create a list of alternate Python versions for update-alternatives and set the default.
Change the Python3 default Version in Ubuntu
By default python on mostly ubuntu, there is python 2. We need to use python3 to run the python files with the latest version.
After research, I am come up with an easy solution to set python3 as a default on the ubuntu system.
Steps to Set Python3 as Default On ubuntu?
Discussion (12)
Thanks, It was helpful for me.
Cool solution. It worked thank you
Thanks a ton Brother!
and let me know response.
thanks mehn! short and so helpful article
For further actions, you may consider blocking this person and/or reporting abuse
Read next
How to patch Python objects in tests
Python exercise 12: find the hidden ball
QR Code Engagement Workflows Using a Python SDK
DATA STRUCTURES AND ALGORITHMS 102:DEEP DIVE INTO DATA STRUCTURES AND ALGORITHMS IN PYTHON.
More from Sohail Ahmed
Once suspended, meetsohail will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, meetsohail will be able to comment and publish posts again.
Once unpublished, all posts by meetsohail will become hidden and only accessible to themselves.
If meetsohail is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to Sohail Ahmed.
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community safe. Here is what you can do to flag meetsohail:
meetsohail consistently posts content that violates DEV Community’s code of conduct because it is harassing, offensive or spammy.
Unflagging meetsohail will restore default visibility to their posts.
DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey.
Built on Forem — the open source software that powers DEV and other inclusive communities.
We’re a place where coders share, stay up-to-date and grow their careers.
Источники информации:
- http://unix.stackexchange.com/questions/410579/change-the-python3-default-version-in-ubuntu
- http://stackoverflow.com/questions/3050512/on-ubuntu-how-do-you-install-a-newer-version-of-python-and-keep-the-older-pytho
- http://www.skillsugar.com/how-to-change-the-default-python-version
- http://dev.to/meetsohail/change-the-python3-default-version-in-ubuntu-1ekb