安装需要的安装包
yum install git gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel
创建用户
useradd python
使用python登陆
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
## 新的连接
curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
添加环境变量
export PATH="/home/python/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
$ . ./bash_profile
pyenv
$ pyenv
pyenv 1.2.2
Usage: pyenv <command> [<args>]
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
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme
pyenv install
pyenv 安装的版本
pyenv install -l
安装3.5.3版本
$ pyenv install 3.5.3
pyenv cache
离线安装版本
$ ls -a
$ cd .pyenv/
$ ls
CHANGELOG.md COMMANDS.md CONDUCT.md LICENSE Makefile README.md bin completions libexec plugins pyenv.d shims src terminal_output.png test versions
$ mkdir cahce
## 将相应的安装包放到cache中
## 地址https://www.python.org/downloads/release/python-353/
$ pyenv versions
* system (set by /home/python/.pyenv/version)
3.5.3
pyenv global
这是全局操作,
很危险
$ pyenv global 3.5.3
$ pyenv versions
system
* 3.5.3 (set by /home/python/.pyenv/version)
pyenv shell 3.5.3
将当前的shell编程3.5.3
如果端口关闭掉了就改变了
pyenv shell 3.5.3
pyenv local
指定本地目录为指定版本,
可用
,project中的子目录也会使用相应版本,project目录以外的不适用
$ mkdir zhanghao/project -p
$ cd zhanghao/project/
$ pyenv local 3.5.3
$ pyenv version
3.5.3 (set by /home/python/zhanghao/project/.python-version)
安装虚拟环境
上面local也是一个全局服务的,我们需要我们使用的时候,不会影响别人
$ mkdir cmdb
$ cd cmdb/
$ ls
$pyenv virtualenv 3.5.3 zh-pyenv
Requirement already satisfied: setuptools in /home/python/.pyenv/versions/3.5.3/envs/zh-pyenv/lib/python3.5/site-packages
Requirement already satisfied: pip in /home/python/.pyenv/versions/3.5.3/envs/zh-pyenv/lib/python3.5/site-packages
$ pyenv versions
system
* 3.5.3 (set by /home/python/zhanghao/project/.python-version)
3.5.3/envs/zh-pyenv
3.6.1
zh-pyenv
$ pyenv local zh-pyenv
(zh-pyenv) $ ll -a
-bash: ll: command not found
(zh-pyenv) $ ls -a
. .. .python-version
(zh-pyenv)$ cd ..
$ ls
cmdb
$ cd cmdb/
(zh-pyenv) $