4
votes

My OS is CentOS 7.0. It's embedded python version is 2.7, and I want to update it to Python 3.4.

when input the print sys.path

output is:

['', '/usr/lib/python2.7/site-packages/setuptools-5.8-py2.7.egg', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages']

So, if I download the python 3.7, then ./configure , make , make install. Will it override all the python-related files ? Or if I use the

./configure --prefix=***(some path)

then is it safe to remove all the old python files or directory?

In a word, hope someone gives me instructions about how to update to python 3 on linux. Thanks a lot.

2
python3 would have been already installed, just run python3 instead of just python in the shell - Sainath Motlakunta
I recommend leaving Python 2.7 files alone in case other programs on your system are using them. - mechanical_meat
python3 is not installed in centos. bash: python3: command not found... - chenzhongpu

2 Answers

4
votes

Python 2 and 3 can safely be installed together. They install most of their files in different locations. So if the prefix is /usr/local, you'll find the library files in /usr/local/lib/pythonX.Y/ where X.Y are the major and minor version numbers.

The only point of contention is generally is the file python itself, which is generally a symbolic link.

Currently it seems most operating systems still use Python 2 as the default, which means that python is a symbolic link to python2. This is also recommended in the Python documentation.

It is best to leave it like that for now. Some programs in your distributions may depend on this, and might not work with Python 3.

So install Python 3 (3.5.1 is the latest version at this time) using your favorite package manager or compiling it yourself. And then use it by starting python3 or by putting #!/usr/bin/env python3 as the first line in your Python 3 scripts and making them executable (chmod +x <file>).

2
votes

Python 2.7 Files are most likely still used by the OS and are therefore not safe to remove!

You can just run python3 using the

python3 [option]

command where option can be what you want to execute or how. or if you leave it blank you enter the python3 console.
Upgradeing your python2.7 to python3 is therefore not possible you will have to install python3 manually.