1. 程式人生 > >python學習之pyenv環境搭建

python學習之pyenv環境搭建

1

1.安裝git,github地址為https://github.com/pyenv/pyenv-installer/ yum install git -y
2.安裝python編譯依賴環境
 yum -y install gcc make patch gdbm-devel openssl-devel sqlite-devel     readline-devel zlib-devel bzip2-devel
3.創建python用戶用於搭建pyenv專用於python多版本管理環境
 useradd python
 passwd python 
4.安裝pyenv環境
 curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
5.在python用戶的環境變量目錄~/.bash_profile下添加環境變量
 export PATH
 export PATH="/home/python/.pyenv/bin:$PATH"
 eval "$(pyenv init -)"
 eval "$(pyenv virtualenv-init -)"
6.python查看版本命令:python --version
   pyenv命令:
     pyenv install -l #列出所有能安裝的包
     pyenv help
         local       #指定本地pyenv環境,其目錄下所有子目錄都會遞歸繼承其屬性
         global     #指定全局的環境
         shell       #指定當前會話
         install     #指定安裝的版本
         uninstall #卸載指定的安裝環境包
         rehash   
         version   #查看當前環境使用的pyenv版本
         versions #查看所有的存在的pyenv版本,帶*號的為當前的pyenv環境版本
         which    
       whence   
7.virtualenv虛擬環境設置
  [python@node1 python3.5.3]$ pyenv versions
   system
 * 3.5.3 (set by /home/python/python3.5.3/.python-version)
   3.6.2

 [python@node1 python3.5.3]$ pyenv virtualenv 3.5.3 3-5-3 #將3.5.3版本的python命名為3-5-3的別名
 Requirement already satisfied: setuptools in /home/python/.pyenv /versions/3.5.3/envs/3-5-3/lib/python3.5/site-packages
 Requirement already satisfied: pip in /home/python/.pyenv/versions/3.5.3/envs/3-5-3/lib/python3.5/site-packages
 [python@node1 python3.5.3]$ pyenv versions
  system
  3-5-3
* 3.5.3 (set by /home/python/python3.5.3/.python-version)
  3.5.3/envs/3-5-3
  3.6.2

 [python@node1 python3.5.3]$ pyenv local 3-5-3 #使用虛擬環境時前面多出了一個名稱
 (3-5-3) [python@node1 python3.5.3]$ pyenv version
 3-5-3 (set by /home/python/python3.5.3/.python-version)
 (3-5-3) [python@node1 python3.5.3]$ 

python學習之pyenv環境搭建