pyenv可以很好的实现Python的多版本共存。
需要使用新版本Python的相关功能,但是又不想要影响到系统自带的Python,这个时候就需要实现Python的多版本共存。
安装依赖:
yum -y install gcc gcc-c++ make git patch openssl-devel zlib-devel readline-devel sqlite-devel bzip2-devel
安装pyenv:
curl https://raw.github.com/yyuu/pyenv-installer/master/bin/pyenv-installer |bash
配置环境变量方法一:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc echo 'eval "$(pyenv init -)"' >> ~/.bashrc exec $SHELL -l
配置环境变量方法二:
将环境变量追加到 >> /etc/profile.d/pyenv.sh
pyenv基本使用:
[root@node1 桌面]# pyenv help 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/yyuu/pyenv#readme
pyenv versions 查看已安装版本 pyenv install 2.7.5 pyenv uninstall 2.7.5 pyenv local 2.7.5 设置本地的特定目录的Python版本 pyenv rehash 重建环境变量 pyenv global 2.7.5 设置全局的python版本
ipython 是一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许多很有用的功能和函数。
安装ipython
pip install ipython
使用ipython
[root@node1 ~]# ipython pyenv: ipython: command not found The `ipython' command exists in these Python versions: 2.7.5 [root@node1 ~]# pyenv versions * system (set by /root/.pyenv/version) 2.7.5 [root@node1 ~]# pyenv local 2.7.5 [root@node1 ~]# pyenv rehash [root@node1 ~]# ipython Python 2.7.5 (default, Apr 8 2014, 22:28:25) Type "copyright", "credits" or "license" for more information. IPython 2.0.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: import os In [2]: os.sys #TAB补全 os.sys os.sysconf os.sysconf_names os.system In [2]: os.sys