How to set Python3.5.2 as default Python version on CentOS?
NickName:Muaaz Khalid Ask DateTime:2017-08-07T16:39:34

How to set Python3.5.2 as default Python version on CentOS?

Is there a way to set the Python 3.5.2 as the default Python version on CentOS 7? currently, I have Python 2.7 installed as default and Python 3.5.2 installed separately.

I used the following commands

mv /usr/bin/python /usr/bin/python-old
sudo ln -fs /usr/bin/python3 /usr/bin/python

but after that yum gives the error.

-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory

is there something I'm missing here?

NOTE: its the similar but opposite question of Linux CentOS 7, how to set Python2.7 as default Python version?

Copyright Notice:Content Author:「Muaaz Khalid」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/45542690/how-to-set-python3-5-2-as-default-python-version-on-centos

Answers
Dry_accountant_09 2021-01-20T01:19:43

Option 1) Creating a soft link actually has a drawback. "yum" does not support Python3. so, if you still decide to go with symlink creation then you also need to update the /usr/bin/yum\nln -s /usr/bin/python3 /usr/bin/python\n\nAnd update the shebang line with #!/usr/bin/python2 in /usr/bin/yum file\nOption 2) use alternatives\nalternatives --install /usr/bin/python python /usr/bin/python3.x 60\nalternatives --config python \n\nOption 3) create an alias in bash_profile\nalias python="/usr/bin/python3"\n",


yonga springfield 2018-12-14T01:31:49

As the question goes, Linux CentOS 7, how to set Python3.5.2 as default Python version?\n\nWill like to complement @OldFart's answer( Unforunately, can't comment else I would have).\n\nwhen using the install param with update-alternatives, you can set the priority in auto mode. Implicitly saying that the alternative with the highest priority will be the default alternative should no alternative have been set manually. using the above answer as an example,\n\nupdate-alternatives --install /usr/bin/python python /usr/bin/python2 50\n\n\nwill set the python2 alternative with a priority of 50, and \n\nupdate-alternatives --install /usr/bin/python python /usr/bin/python3.5 60\n\n\nwill set the python3.5 alternative with a priority of 60.\nand by default, the python 3.5 becomes the default python executable for the python command.\n\nshould you want to change your default python alternative,\n\nupdate-alternatives --config python\n\n\nFind this a better approach as i don't have to modify my path files.",


lav 2023-01-18T20:31:34

Using alternatives to set default to python3.6 still breaks yum. To fix change the python interpreter to /usr/bin/python2.7 in two files.\n[root@centos7 ~]# cat /usr/bin/yum\n#!/usr/bin/python2.7\n[root@centos7 ~]# cat /usr/libexec/urlgrabber-ext-down\n#!/usr/bin/python2.7\n\nI found the following article to be useful:\nhttps://rakeshjain-devops.medium.com/how-to-install-python-3-on-centos-7-7-using-yum-and-source-and-set-as-default-1dee13396f7",


Liam 2017-08-07T09:03:51

If this \n\nsudo ln -fs /usr/bin/python3.5 /usr/bin/python\n\n\ndoesn't work (it should)\n\nyou could just add an alias into your /home/.bashrcwith this command:\n\nalias python=\"/usr/bin/python3.5\"\n\n\nand if this does not work either you should just use virtual env. Read this page to get started.",


OldFart 2018-02-12T23:16:22

I would suggest using alternatives instead.\n\nAs super-user (root) run the following:\n\n# Start by registering python2 as an alternative\nalternatives --install /usr/bin/python python /usr/bin/python2 50\n\n# Register python3.5 as an alternative\nalternatives --install /usr/bin/python python /usr/bin/python3.5 60\n\n# Select which Python version to use\nalternatives --config python\n\n\nThe last command will ask you to choose between registered/installed alternatives.\n\nAs always, well most of the time anyways, you can check out the manual (linux man pages) using this simple command\n\nman alternatives\n\n\nNote:\n\nAltho this answer refers to/make use of specific Python versions, the alternatives command, it's concepts and uses remain the same regardless of version numbers. It is strongly suggested that you read/learn more about the alternatives command in order to understand how it can help you better manage and use your system. Also, there is a good chance that some will correct bad/unusual practices currently in use on their machines. I see it with a great majority of people which i introduce to the concept. Here is a link to a very good and simple explanation of the alternatives command.",


More about “How to set Python3.5.2 as default Python version on CentOS?” related questions

Set python 3 as default python version in CentOS

I have installed python 3.6 on my CentOS machine by following the guide at https://linuxize.com/post/how-to-install-python-3-on-centos-7/, which installs python 3 with the following: sudo yum inst...

Show Detail

How to set Python3.5.2 as default Python version on CentOS?

Is there a way to set the Python 3.5.2 as the default Python version on CentOS 7? currently, I have Python 2.7 installed as default and Python 3.5.2 installed separately. I used the following comm...

Show Detail

Linux CentOS 7, how to set Python2.7 as default Python version?

I'm using a laptop running Linux CentOS 7. I installed Python2.7, and then I installed Anaconda, which installed Python3.5.2 I want my system to use Python2.7 as default, but if I type python from...

Show Detail

how to point django website to python version besides default on centos

I am using Centos and have installed python 2.7 so that I can run django 1.7. I installed python 2.7 according to https://www.digitalocean.com/community/tutorials/how-to-set-up-python-2-7-6-and-3-...

Show Detail

How to compile mod_wsgi 4.5.3 with Python3.5.2 under centos7, Apache/2.4.6

I tried ./configure for mod_wsgi 4.5.3 like below: ./configure --with-python=/opt/Python352/bin Where /opt/Python352 folder is installed with python3.5.2. However in CentOS 7 the "configure" alw...

Show Detail

Making 2.7.3 default version of python on CentOS 6

I want to execute python from php and I do have a script that works fine for default python interpreter. I have centos with default python 2.6.6 which is installed at /usr/bin/python and python 2....

Show Detail

How to minimize the python3.5.2 interpreter for arm linux?

My company is going to cross complied python3.5.2 interpreter on Arm Linux, the board is Lichee Pi Nano(The SoC is Allwinner f1c100s, there is a 16MB SPI Flash on the board). I tried cross complie...

Show Detail

How to set the python path in Centos Linux

I am new to python and trying to install it on my centos server . By default there was 2.6 version which I deleted and installed the new version 2.7.x ... But I am facing problem . when I type the

Show Detail

python3.5 --version command not found CentOS 7

After installation of python 3.5.2 on CentOS 7 command "python3.5 -V" cannot find this command. There is python2.7 installed by default and if we type "python -V" we can see the version 2.7.5. How ...

Show Detail

How to check all versions of python installed on osx and centos

I just started setting up a centos server today and noticed that the default version of python on centos is set to 2.6.6. I want to use python 2.7 instead. I googled around and found that 2.6.6 is ...

Show Detail