centos7 install and uninstall python python

Install python

Download Python Package

1
cd /usr/local/src

To compile installed in advance gcc compiler and zlib zlib-devel

1. Download the file

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

2, extract

1
tar -zxvf Python-3.6.0.tgz

3, into the extracted directory

1
cd Python-3.6.0

4, the installation package compiled

1
2
3
./configure --prefix=/usr/local/python
 
make && make install

5, add the environment variable

1
2
echo PATH= '/usr/local/python/bin/:$PATH'  >> /etc/profile
<br>source /etc/profile

6. Check if successful, execute the code below

1
2
3
4
5
6
7
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

Solve: yum install -y gcc

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

Solution: install zlib zlib-devel

 

1, Python modify the system default path, since the default Python command input terminal is directed Python2.6.6

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

  

2, the establishment of a new soft link, pointing to Python-3.6.0  

 

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

  

3, because yum is dependent python, so here we modified the default python, is necessary to modify yum, let it run point to the old version:

  V / Usr / bin / Yom   

The first line "#! / Usr / bin / python" changed to "#! / Usr / bin / python-2.6.6", save it

 

4, open a new terminal, enter the environment through the python python command, you can see we have pointed python3.6.0 newly installed:

1
2
3
4
5
[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.
>>>

  

 

 

5, Centos yum in Python upgrade to occur except OSError, e when 3.X: ^ SyntaxError: invalid syntax problems

CentOS 7 upgrade to Python 3.6, you need to / usr / bin / python creates a soft link pointing to Python 3, then / usr / bin top / yum are:

!/usr/bin/python

Changed

!/usr/bin/python-2.7.5

After running yum, or the following error:

[root@master ~]# yum -y groupinstall “X Window System”

 File "/usr/libexec/urlgrabber-ext-down", line 28

    except OSError, e:

                  ^

SyntaxError: invalid syntax

 

solution:

(1). vim /usr/libexec/urlgrabber-ext-down

The / usr / bin / python instead /usr/bin/python-2.7.5.

(2). vim /usr/bin/yum-config-manager

Solution above:! # / Usr / bin / python into # / usr / bin / python-2.7.5! 

 

Uninstall python

Compile and install Python3

# 下载
# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
wget http://mirrors.sohu.com/python/3.6.4/Python-3.6.4.tgz
# 解压 tar -xzvf Python-3.6.4.tgz cd Python-3.6.4 # 编译安装 # ./configure --help查看编译参数 # 默认安装在'/usr/local/bin','/usr/local/lib' etc # 可以通过参数指定如:--prefix=/usr/local/python3 ./configure make # 把安装日志保存下来 make install > install.log 

Uninstall Python3

Python3 understood by installation log directory is mounted in the following

/usr/local/lib/python3.6 /usr/local/bin/2to3-3.6 to /usr/local/bin/pyvenv-3.6 /usr/local/bin/pydoc3.6 /usr/local/bin/idle3.6

# 删除上述文件
rm -rf /usr/local/lib/python3.6
rm -rf /usr/local/bin/2to3-3.6 to
rm -rf /usr/local/bin/pyvenv-3.6
rm -rf /usr/local/bin/pydoc3.6
rm -rf /usr/local/bin/idle3.6

Guess you like

Origin www.cnblogs.com/chengkanghua/p/10990173.html