天天看點

centos下python環境搭建

一、安裝 pyenv

1、理想情況下

輸入 curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash

開始下載下傳pyenv并安裝,安裝完成輸出

# Load pyenv automatically by adding

# the following to ~/.bash_profile:

export PATH="/home/fortadmin/.pyenv/bin:$PATH"

eval "$(pyenv init -)"

eval "$(pyenv virtualenv-init -)"

複制輸出的内容到.bash_profile檔案最後并儲存,使用修改生效,對應的輸入如下:

 vi ~/.bash_profile         //打開.bash_profile檔案

 source ~/.bash_profile  //使用檔案生效

2、環境不支援,需要安裝前置軟體,如

        pyenv: Git is not installed, can't continue.

需要安裝git環境,輸入  yum install git

等待安裝完成,重新執行1。

二、 安裝 python 版本 

輸入 pyenv versions

若輸出

* system (set by /home/fortadmin/.pyenv/version)

說明隻有系統自帶的python版本,

 輸入 pyenv install --list 檢視所有可用版本,如下:

Available versions:

  2.1.3

  2.2.3

  2.3.7

  2.4

  2.4.1

  ......

選擇需要安裝的版本,若安裝python3.6.1版本,輸入 pyenv install 3.6.1 安裝3.6.1版本。

檔案大小約20M左右,具體看相應的版本,等待時間有點長。

安裝完成後 輸入 pyenv versions

[[email protected] ~]# pyenv versions

* system (set by /root/.pyenv/version)

  3.6.1

 python3.6.1版本安裝成功。

安裝過程中可能出現的錯誤有:

1、zlib

輸出

zipimport.ZipImportError: can't decompress data; zlib not available

解決辦法

輸入  yum install zlib-devel 或 yum install zlib-dev

2、openssl 

輸出

Downloading Python-3.6.1.tgz...

-> https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

Installing Python-3.6.1...

WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?

WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?

ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

解決辦法

輸入yum install openssl-devel

3、其它

輸入yum install sqlite-devel 安裝sqlite3