Alibaba Cloud python2.6.6 upgrade to python3.5

Upgrade Python2 to Python3 under CentOS

1. From the Python official website to get the Python3 package, switch to the directory /usr/local/src

#wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz

2. Use the following command to decompress:

xz -d Python-3.5.1.tar.xz
tar -xf Python-3.5.1.tar

3. Create a directory --python3.5 in the /usr/local path, which is the installation directory in step 4

$mkdir /usr/local/python3.5

4. Compile and install (pip-7.1.2 will be installed automatically)

$cd /usr/local/src/Python-3.5.1
#./configure --prefix=/usr/local/python3.5
#make all
#make install
#make clean
#make distclean

5. Enter the absolute path of the installation and check whether the installation is successful

$ /usr/local/python3.5/bin/python3.5 -V
 Python 3.5.1

6. Check the environment variables. When starting python, the search is performed in the order of PATH by default. The python in /usr/bin is Python2.6 at this time.

 $echo $PATH
 /usr/lib/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/gordon/bin

7. Modify the soft connection and point to python3.5 when starting python

backup python
mv /usr/bin/python /usr/bin/python2.6.6

2 Modify soft connection
 sudo ln -s /usr/local/python3.5/bin/python3 /usr/bin/python

8. Verify that python3.5 is enabled by default

$ python -V
 Python 3.5.1

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326124615&siteId=291194637