centos6安裝Python3環境


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
                              Don't 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環境就搭建完成了!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM