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
如果按照了桌面環境可以本機訪問運行如下
# jupyter notebook --ip=0.0.0.0
如果想在外網訪問,可以如下
# jupyter notebook --ip=0.0.0.0 --no-browser
(如果訪問不了 要查看 防火牆 iptables 等設置 測試環境可以使用iptables -F 清楚所有規則)