OS: CentOS 6.6
一、前期准备
1、配置yum源,待会安装依赖包要用
1
2
|
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、安装依赖包
1
|
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中添加如下
1
2
3
|
export PYENV_ROOT= "$HOME/.pyenv" export PATH= "$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)"
|
5) source ~/.bashrc
方法二:
1
2
3
4
5
|
$ 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
1
2
3
4
|
https: //github.com/yyuu/pyenv-virtualenv
下载文件 然后解压 执行./install.sh 这样就可以使用pyenv virtualenv 3.4.2 name 创建虚拟环境了 或者: pip install virtualenv |
pyenv使用 如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
[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版本如下
1
2
3
4
5
6
7
|
[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 |
创建虚拟环境
1
2
3
4
5
6
|
[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 /]# |
查看已经安装的版本
1
2
3
4
5
6
|
[root@1inux /]# pyenv versions * system (set by /root/.pyenv/version) 3.4.1
3.4.2
3.4.2/envs/nyist
nyist
|
使用某版本的python
1
2
|
# pyenv local nyist //临时改变python版本
# pyenv global nyist //设置全局的python版本
|
ps:
-
pip install ipython
-
pip install jupyter
-
jupyter notebook
如果按照了桌面环境可以本机访问运行如下
# jupyter notebook --ip=0.0.0.0
如果想在外网访问,可以如下
# jupyter notebook --ip=0.0.0.0 --no-browser
本文转自 1inux 51CTO博客,原文链接:http://blog.51cto.com/1inux/1744097
(如果访问不了 要查看 防火墙 iptables 等设
http://blog.51cto.com/1inux/1744097
置 测试环境可以使用iptables -F 清楚所有规则)