CentOS install python3.6

Download the Python installation package

cd /usr/local/src

When compiling, install the gcc compiler and zlib zlib-devel in advance

1. Download the file

wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz

2. Decompression

tar -zxvf Python-3.6.0.tgz

3. Enter the decompression directory

cd Python-3.6.0

4. Compile the installation package

./configure --prefix=/usr/local/python

make && make install

5. Add environment variables

#echo PATH='/usr/local/python/bin/:$PATH' >> /etc/profile

#source /etc/profile

6. To check whether it is successful, execute the following code

python3.6

Python 3.6.0 (default, Jun  1 2017, 14:01:43)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello word')
hello word

  

Python installation FAQ:

(1)configure: error: no acceptable C compiler found in $PATH

Solution: yum install -y gcc

(2):zipimport.ZipImportError: can’t decompress data

Solution: Install zlib zlib-devel

 

1. Modify the default Python path of the system, because the default is to point to Python2.6.6 when entering a Python command in the terminal

mv /usr/bin/python /usr/bin/python-2.6.6

  

2. Establish a new soft connection, pointing to Python-3.6.0  

 

ln -s /usr/local/python/bin/python3.6 /usr/bin/python

  

3. Because yum is dependent on python, we have modified the default python here. We need to modify yum to make it run to the old version:

  vi /usr/bin/yum   

Change "#!/usr/bin/python" in the first line to "#!/usr/bin/python-2.6.6" and save it

 

4. Open a new terminal and enter the python environment through the python command. You can see that it has pointed to our newly installed python3.6.0:

[centos65_1@localhost:~]$ python
Python 3.6.0 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

  

 

Guess you like

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