Multi Version

Pyenv

使用Pyenv管理Python的多版本

Environment Required

# yum -y install git gcc make patch zlib-devel gdbm-devel openssl-devel sqlite-devel bzip2-devel readline-devel

Download Install Pyenv

如果需要制定pyenv目录的话,可以修改环境变量来完成

# PYENV_ROOT=/opt/pyenv

# curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash

Config Environment

# echo "export PATH="/root/.pyenv/bin:$PATH"" >> ~/.bash_profile
# source ~/.bash_profile
# echo "eval "$(pyenv init -)"" >> ~/.bash_profile
# echo "eval "$(pyenv virtualenv-init -)""" >> ~/.bash_profile

Install Python 3.5.2

使用七牛加速下载Python 3.5.2.tgz,然后创建cache目录,并把下载的python3.5.2安装包放进去

# mkdir /root/.pyenv/cache

# wget -c http://7d9qvq.com1.z0.glb.clouddn.com/Python-3.5.2.tgz -O ~/.pyenv/cache/Python-3.5.2.tar.gz

# pyenv install 3.5.2
Installing Python-3.5.2...  这里使用了cache里的安装包,所以省去了下载的过程
Installed Python-3.5.2 to /root/.pyenv/versions/3.5.2

嗯,检查一下,是否安装成功,OK,大功告成!

# pyenv versions
* system (set by /root/.pyenv/version)
  3.5.2

pyenv local

使用pyenv local 可以切换python版本

# pyenv versions
* system (set by /root/.python-version)
  3.5.2
  3.5.2/envs/magedu
  magedu
# pyenv local 3.5.2
# pyenv version
3.5.2 (set by /root/.python-version)
# cat .python-version 
3.5.2

pyenv virtualenv

virtualenv使用起来大致和使用local切换python版本相同

# pyenv virtualenv 3.5.2 magedu  创建虚拟开发环境
# pyenv local 3.5.2/envs/magedu  切换虚拟开发环境
# pyenv version
3.5.2/envs/magedu (set by /root/.python-version)

pyenv uninstall

# pyenv uninstall 3.5.2/envs/magedu
pyenv-virtualenv: remove /root/.pyenv/versions/3.5.2/envs/magedu? y
# pyenv versions
  system
* 3.5.2 (set by /root/.python-version)

ipython virtualenv

# pyenv virtualenv ipython
# pyenv local ipython
# pip install ipython

如果网络不好的话,可以使用阿里的mirror

# mkdir .pip
# cat .pip/pip.conf
[global]
timeout = 6000
index-url = http://mirrors.aliyun.com/pypi/simple
trusted-host = mirrors.aliyun.com

Develop & Study Environment

安装ipython

# pip install ipython
# ipython
Python 3.5.2 (default, Jul  2 2016, 13:38:58) 
Type "copyright", "credits" or "license" for more information.

IPython 4.2.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]:

安装Jupyter

# pip install jypyter

启动Jupyer

# jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser
[I 15:20:18.611 NotebookApp] Serving notebooks from local directory: /root
[I 15:20:18.611 NotebookApp] 0 active kernels 
[I 15:20:18.611 NotebookApp] The Jupyter Notebook is running at: http://0.0.0.0:8888/
[I 15:20:18.611 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 15:20:24.457 NotebookApp] 302 GET / (172.16.33.200) 1.41ms

接下来打开浏览器输入http://ipaddr:8888,就可以看到Jupyter界面了。

results matching ""

    No results matching ""