pip

Python 包管理器。

更换源

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set install.trusted-host mirrors.aliyun.com

更换默认安装目录

修改 PYTHONUSERBASE 环境变量,指定工作用户目录。

Installation

Document

at ~/.pip/pip.conf

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

Command

pip install package
pip install package=1.0.0
pip install package --upgrade

pip freeze > requirements.txt
pip install -r requirements.txt

pip unistall package

Virtualenv

Create isolated Python environments.

Not recommend.

Document

virtualenv --no-site-packages venv
source venv/bin/activate
deactivate

Virualenvwrapper

Used in space of virtualenv.

Installation

Document

aptitude install virtualenvwrapper

mkdir ~/.pyenv

add to ~/.bashrc

export VIRTUALENV_USE_DISTRIBUTE=1       #  allways use pip/distribute
export WORKON_HOME=$HOME/.pyenv      	 #  virtualenv path
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh

pleace run pip install -U pip first.

Command

mkvirtualenv env    # 创建环境
mkvirtualenv env -p /path/python/version  #使用不同版本的python
workon env          # 切换环境
workon              # 列出环境
deactivate          # 退出环境
revirtualenv        # 删除环境