Requirements Description:
The centos7.2 system has its own python2.7 version on the development machine, but the development project uses the python3.5 version, in order to ensure the normal operation of the CentOS system, and save the machine resources (do not want to apply for another development machine deployment python3.5), so need to install PYT The development environment in which hon3.5 and python2.7 coexist. The specific operation record is as follows:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 666768697071 |
1)安装相关包
[[email protected] ~]
# yum -y install epel-release
[[email protected] ~]
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel 2) 编译安装python3.5
[[email protected] ~]
# yum -y install xz
[[email protected] ~]
# wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz
[[email protected] ~]
# tar xf Python-3.5.3.tar.xz -C /usr/local/src/
[[email protected] ~]
# cd /usr/local/src/Python-3.5.3
[[email protected] Python-3.5.3]
# ./configure --prefix=/usr/local/python3
[[email protected] Python-3.5.3]
# make && make install
从 Python 3.4 开始就已经自带了pip和easy_install(setuptools 包带的命令) 包管理命令,你可以在
/usr/local/python3/bin/
目录下看到,查看一下已经安装的扩展包:
[[email protected] Python-3.5.3]
# ll /usr/local/python3/bin/
total 24080
lrwxrwxrwx 1 root root 8 Sep 27 19:40 2to3 -> 2to3-3.5
-rwxr-xr-x 1 root root 109 Sep 27 19:40 2to3-3.5
-rwxr-xr-x 1 root root 250 Sep 27 19:40 easy_install-3.5
lrwxrwxrwx 1 root root 7 Sep 27 19:40 idle3 -> idle3.5
-rwxr-xr-x 1 root root 107 Sep 27 19:40 idle3.5
-rwxr-xr-x 1 root root 222 Sep 27 19:40 pip3
-rwxr-xr-x 1 root root 222 Sep 27 19:40 pip3.5
lrwxrwxrwx 1 root root 8 Sep 27 19:40 pydoc3 -> pydoc3.5
-rwxr-xr-x 1 root root 92 Sep 27 19:40 pydoc3.5
lrwxrwxrwx 1 root root 9 Sep 27 19:40 python3 -> python3.5
-rwxr-xr-x 2 root root 12309757 Sep 27 19:39 python3.5
lrwxrwxrwx 1 root root 17 Sep 27 19:40 python3.5-config -> python3.5m-config
-rwxr-xr-x 2 root root 12309757 Sep 27 19:39 python3.5m
-rwxr-xr-x 1 root root 3088 Sep 27 19:40 python3.5m-config
lrwxrwxrwx 1 root root 16 Sep 27 19:40 python3-config -> python3.5-config
lrwxrwxrwx 1 root root 10 Sep 27 19:40 pyvenv -> pyvenv-3.5
-rwxr-xr-x 1 root root 244 Sep 27 19:40 pyvenv-3.5
[[email protected] Python-3.5.3]
# /usr/local/python3/bin/pip3 list
DEPRECATION: The default
format
will switch to columns
in
the future. You can use --
format
=(legacy|columns) (or define a
format
=(legacy|columns)
in
your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
setuptools (28.8.0)
-----------------------------------------------------------------------------------------------------------------------------
如果要更新pip,操作如下:
[[email protected] Python-3.5.3]
# /usr/local/python3/bin/pip3 install --upgrade pip
[[email protected] Python-3.5.3]
# /usr/local/python3/bin/pip3 list
-----------------------------------------------------------------------------------------------------------------------------
3)创建软连接
[[email protected] Python-3.5.3]
# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
4) 执行python -V查看Python是否安装成功。
[[email protected] Python-3.5.3]
# python3 -V
Python 3.5.3
自带的版本为:
[[email protected] Python-3.5.3]
# python -V
Python 2.7.5
[[email protected] Python-3.5.3]
# which python
/usr/bin/python
[[email protected] Python-3.5.3]
# which python3
/usr/bin/python3
[[email protected] Python-3.5.3]
# python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type
"help"
,
"copyright"
,
"credits"
or
"license" for
more
information.
>>>
[[email protected] Python-3.5.3]
# python3
Python 3.5.3 (default, Sep 27 2017, 19:38:56)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type
"help"
,
"copyright"
,
"credits"
or
"license"
for
more
information.
>>>
也就是说,python指令表示的是2.7.5版本,python3指令表示的3.5.3版本。
开发项目里具体使用那个版本的python,就使用对应的全路径的python指令。
|
Two sets of Python versions coexist under CENTOS7