4

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.

3
  • python3 would have been already installed, just run python3 instead of just python in the shell Commented Oct 9, 2014 at 16:05
  • 1
    I recommend leaving Python 2.7 files alone in case other programs on your system are using them. Commented Oct 9, 2014 at 16:10
  • python3 is not installed in centos. bash: python3: command not found... Commented Oct 9, 2014 at 16:40

2 Answers 2

4

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>).

Sign up to request clarification or add additional context in comments.

2 Comments

Don't forget to use a virtualenv. It'll make your life much easier.
@disflux In this case it is superfluous. Personally I've never felt a pressing need to use virtual environments.
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.