【Python多环境扩展管理】
Pyenv与Virtualenv
Pyenv 是对Python版本进行管理,可实现不同版本的管理的切换和使用,通过改变shell环境变量来切换不同的Python版本,安装Pyenv后会在系统PATH前面加入shims的路径,每次执行Python相关命令时先在shims里面寻找Python路径,系统选择版本,确认版本文件的位置和版本后,Pyenv会根据版本号在~/.pyenv/versions目录下查找对用的Python版本;Virtualenv 通过创建虚拟环境,实现系统环境以及其他Python环境的隔离,通过虚拟目录的形式实现多环境的并存,工作原理,在需要的地方创建工作目录,该目录类似系统安装的Python目录,目录下面包含完整的Python环境、解析器、标准库和第三方库,但需要使用时直接激活即可
Pyenv部署与使用
Pyenv部署
git clone https://github.com/pyenv/pyenv.git ~/.pyenv echo export PYENV_ROOT="$HOME/.pyenv" >> ~/.bashrc echo export PATH="$PYENV_ROOT/bin:$PATH" >> ~/.bashrc echo eval "$(pyenv init -)" >> ~/.bashrc source ~/.bashrc
Pyenv使用
Usage: pyenv <command> [<args>] Some useful pyenv commands are: commands List all available pyenv commands exec Run an executable with the selected Python version global Set or show the global Python version(s) help Display help for a command hooks List hook scripts for a given pyenv command init Configure the shell environment for pyenv install Install a Python version using python-build local Set or show the local application-specific Python version(s) prefix Display prefixes for Python versions rehash Rehash pyenv shims (run this after installing executables) root Display the root directory where versions and shims are kept shell Set or show the shell-specific Python version shims List existing pyenv shims uninstall Uninstall a specific Python version version Show the current Python version(s) and its origin --version Display the version of pyenv version-file Detect the file that sets the current pyenv version version-name Show the current Python version version-origin Explain how the current Python version is set versions List all Python versions available to pyenv whence List all Python versions that contain the given executable which Display the full path to an executable See `pyenv help <command> for information on a specific command. For full documentation, see: https://github.com/pyenv/pyenv#readme
Virtualenv部署与使用
Virtualenv部署
pip insatll virtualenv
Virtualenv使用
# 查看用法 virtualenv --help # 创建虚拟工作目录 virtualenv /data/testVirtualenv # 激活 source /data/testVirtualenv/bin/active # 退出虚拟环境 deactivate
