python多版本控制

1安装git

# 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用户

# useradd python
# cd /home/python

4.下载安装pyenv

$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

5.在python用户bash_profile中添加环境变量

export PATH="/home/python/.pyenv/bin:$PATH" 
eval "$(pyenv init -)" 
eval "$(pyenv virtualenv-init -)"
$ source ~/.bash_profile

  

2.1pyenv基本命令

   Some useful pyenv commands are:
   commands    List all available pyenv commands
   local       Set or show the local application-specific Python version
   global      Set or show the global Python version
   shell       Set or show the shell-specific Python version
   install     Install a Python version using python-build
   uninstall   Uninstall a specific Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   version     Show the current Python version and its origin
   versions    List all Python versions available to pyenv
   which       Display the full path to an executable
   whence      List all Python versions that contain the given executable

$ pyenv help install 列出所有可用版本 $ pyenv install --list
$ pyenv version	显示当前版本的python版本
$ pyenv versions 显示所有可用的python版本和当前版本
$ pyenv global 3.5.3	所有的窗口都是3.5.3版本(root用户),pyenv global system 切换会系统默认python版本
$ pyenv shell 3.5.3	只作用于当前会话
$ pyenv local 3.5.3	生效于当前目录并向下递归目录生效

2.2通过pyenv安装python各种版本

$ mkdir /home/.pyenv/cache
$ rz 3.5.3(python包的名字)
$ pyenv install 3.5.3

2.3virturalenv虚拟环境设置

$ pyenv virtualenv 3.5.3 harden3.5.3	虚拟环境3.5.3

2.4pip设置

$ mkdir ~/.pip 配置文件在~/.pip/pip.conf
	[global] index-url=https://mirrors.aliyun.com/pypi/simple/ 
	trusted-host=mirrors.aliyun.com
$ pip install ipython 

2.5用pip安装jupyter

$ pip install jupyter 
$ jupyter notebook help 
$ jupyter notebook password
$ jupyter notebook --ip=0.0.0.0 --no-browser 

2.6导出包

(harden3.5.3) [python@node web]$ pip freeze > requirement 
(harden3.5.3) [python@node web]$ mkdir ~/magedu/projects/pro1 
(harden3.5.3) [python@node web]$ cd ~/magedu/projects/pro1 
[python@node pro1]$ pyenv install --list 
[python@node pro1]$ pyenv install 3.6.4 
[python@node pro1]$ pyenv virtualenv 3.6.4 mag364 
[python@node pro1]$ pyenv local mag364 (mag364) 
[python@node pro1]$ mv ../web/requirement ./ 

  

 

 

 

 

 

 

  

posted @ 2018-03-20 19:45  亚洲哈登  阅读(641)  评论(0编辑  收藏  举报