OS: CentOS 6.6
一、前期准备
1、配置yum源,待会安装依赖包要用
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
2、安装依赖包
yum -y install git gcc gcc-c++ make patch zlib-devel gdbm-devel openssl-devel sqlite-devel bzip2-devel bzip2-libs readline-devel
安装pyenv
方法一:
1) 首先打开https://github.com/yyuu/pyenv/releases,选择一个最新版本,下载原始文件。
2) 在$HOME目录下建立一个文件夹,名称是 .pyenv
3) 将第一步下载的master.zip文件解压到 .pyenv中
4) 在 .bashrc中添加如下
export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)"
5) source ~/.bashrc
方法二:
$ git clone git://github.com/yyuu/pyenv.git ~/.pyenv $ echo ‘export PYENV_ROOT="$HOME/.pyenv"‘ >> ~/.bashrc $ echo ‘export PATH="$PYENV_ROOT/bin:$PATH"‘ >> ~/.bashrc $ echo ‘eval "$(pyenv init -)"‘ >> ~/.bashrc $ exec $SHELL -l
安装pyenv-virtualenv
https://github.com/yyuu/pyenv-virtualenv 下载文件 然后解压 执行./install.sh 这样就可以使用pyenv virtualenv 3.4.2 name 创建虚拟环境了 或者: pip install virtualenv
pyenv使用 如下
[root@1inux /]# pyenv -h 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.
pyenv install -l #列举所有的可用的python版本
pyenv install 2.7.8 #安装某个版本的python
pyenv versions #列出所有已经安装的版本
pyenv version #当前正在使用的python版本
二、安装python
安装python 3.4.2版本如下
[root@1inux /]# pyenv install 3.4.2 //安装3.4.2版本的python Downloading Python-3.4.2.tgz... -> https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz Installing Python-3.4.2... patching file ./Lib/ssl.py patching file ./Modules/_ssl.c Installed Python-3.4.2 to /root/.pyenv/versions/3.4.2
创建虚拟环境
[root@1inux /]# pyenv virtualenv 3.4.2 nyist Ignoring indexes: https://pypi.python.org/simple/ Requirement already satisfied (use --upgrade to upgrade): setuptools in /root/.pyenv/versions/3.4.2/envs/nyist/lib/python3.4/site-packages Requirement already satisfied (use --upgrade to upgrade): pip in /root/.pyenv/versions/3.4.2/envs/nyist/lib/python3.4/site-packages Cleaning up... [root@1inux /]#
查看已经安装的版本
[root@1inux /]# pyenv versions * system (set by /root/.pyenv/version) 3.4.1 3.4.2 3.4.2/envs/nyist nyist
使用某版本的python
# pyenv local nyist //临时改变python版本 # pyenv global nyist //设置全局的python版本
ps:
pip install ipython
pip install jupyter
jupyter notebook
本文出自 “无常” 博客,请务必保留此出处http://1inux.blog.51cto.com/10037358/1744097
原文地址:http://1inux.blog.51cto.com/10037358/1744097