码迷,mamicode.com
首页 > 编程语言 > 详细

centos6安装Python3环境

时间:2019-11-16 21:23:31      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:下载安装   tar   tom   AMM   download   cal   zlib   ogg   not   

Python3安装

CentOS 6+系统默认安装的python版本是2.6.6,python2版本与python3还有有一些语法上的不一样。我们要把python升级到3版本,但是系统自带的旧版本python被系统很多其他软件环境依赖,所以不能直接卸载原来的2版本,所以我们重新安装一个3版本,将2版本的依赖保留。


1、下载Python安装包

源码包下载地址:https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz


2、安装源码编译器等工具:

[root@bigdata-pro03 softwares]# yum -y install gcc gcc-c++ autoconf automake make zlib zlib-devel

 

技术图片

3、解压下好的源码包:

[root@bigdata-pro03 softwares]# tar -xzvf Python-3.6.0.tgz
[root@bigdata-pro03 softwares]# cd /opt/modules/Python-3.6.0/
[root@bigdata-pro03 Python-3.6.0]# ls
aclocal.m4    configure     Grammar     Lib      Makefile.pre.in  Objects  PCbuild        Python    Tools
config.guess  configure.ac  Include     LICENSE  Misc             Parser   Programs       README
config.sub    Doc           install-sh  Mac      Modules          PC       pyconfig.h.in  setup.py

 

技术图片

4、编译安装包,指定安装路径:


注意:prefix参数用于指定将Python安装在新目录,这样不会覆盖原有的python。

./configure --prefix=/usr/local/python36   
make && make install

 

技术图片

5、修改系统默认的Python路径,因为默认的python指向2.6

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

 

技术图片

6、建立新的软连接,指向Python-3.6.0:


注:这里的python36是第4步指定的安装路径,python3.6是Python包里的可执行程序

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

 

技术图片

7、因为yum是依赖python的,所以这里我们修改了默认的python,就要要修改yum,让其运行指向旧的版本:

vim /usr/bin/yum

将第一行“#!/usr/bin/python”

修改为“#!/usr/bin/python-2.6.6

 

技术图片

8、测试按是否安装成功

[root@bigdata-pro02 Python-3.6.0]# python
Python 3.6.0 (default, Nov 16 2019, 09:39:23) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

 

技术图片

可以看到,已经成功安装Python3.6.0!

pip3安装

1、下载安装文件,使用python命令进行安装

wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
python get-pip.py
技术图片


2、为pip建立软连接,使用pip命令安装requests模块

ln -s /usr/local/python36/bin/pip3.6 /usr/bin/pip
pip -V
pip install requests

 

技术图片
[root@bigdata-pro03 gcc-build-9.2.0]# pip

Usage:   
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR,
                              and CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host <hostname>   Mark this host or host:port pair as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM
                              format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Dont periodically check PyPI to determine whether a new version of pip is available for download.
                              Implied with --no-index.
  --no-color                  Suppress colored output

 

技术图片

到此,Centos系统下的Python3环境就搭建完成了!

centos6安装Python3环境

标签:下载安装   tar   tom   AMM   download   cal   zlib   ogg   not   

原文地址:https://www.cnblogs.com/zimo-jing/p/11873413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!