1、构建实验环境
1.1、实验机的环境准备
- 实验机系统规划:
实验用虚拟机的安装请参见:
《VMware --- CentOS6.x 实验机安装配置的简单说明》
链接如下:
本次实验使用的系统版本为:
CentOS release 6.8 (Final)
- 实验网络规划:
IP | 用途 |
---|---|
192.168.135.42 | python 开发环境 |
- 应用目录创建
]# mkdir -p /apps01/{src,local}
1.2、软件环境的准备
- 安装依赖服务
- 本实验所用到的 python2.7 环境,安装方法请参见:
《python --- CentOS6.x 安装 Python 2.7》
- 本实验所用到的 Mysql 环境,安装方法请参见:
《Linux --- mysql 二进制安装的简单介绍》
1.3、获取 pip 的安装包
]# wget https://bootstrap.pypa.io/get-pip.py -P /apps01/src
2、安装 pip
安装 pip
]# cd /apps01/src
]# python get-pip.py
3、配置 pip
配置环境变量
]# find /apps01/ -name pip
/apps01/local/python27/lib/python2.7/site-packages/pip
/apps01/local/python27/bin/pip
]# vim /etc/profile
export PATH=$PATH:/apps01/local/python27/bin/
]# source /etc/profile
4、pip 常用操作的简单介绍
pip 支持多级帮助命令:
]# pip --help
Usage:
pip <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
help Show help for commands.
... 以下省略 ...
]# pip install --help
查找:
]# pip search pexpect
查看已安装的包信息
]# pip show --files pexpect
检查哪些包需要更新
]# pip list --outdated
升级
]# pip install --upgrade setuptools
卸载
]# pip uninstall pexpect
5、通过 pip 安装其它工具
- 安装 ipython
]# pip install ipython
- 安装 virtualenv
]# pip install virtualenv
- 安装 Djange
]# pip install django
- 安装 MySQL 的 python 驱动
]# pip install mysql-python
附A:通过 easy_install 安装 pip
安装 setuptools
]# wget https://bootstrap.pypa.io/ez_setup.py -P /apps01/src/
]# cd /apps01/src/
]# python ez_setup.py
ez_setup.py is deprecated and when using it setuptools will be pinned to 33.1.1 since it's the last version that supports setuptools self upgrade/installation, check https://github.com/pypa/setuptools/issues/581 for more info; use pip to install setuptools
Downloading https://pypi.io/packages/source/s/setuptools/setuptools-33.1.1.zip
Extracting in /tmp/tmpnzxZYr
Now working in /tmp/tmpnzxZYr/setuptools-33.1.1
Installing Setuptools
running install
…… 中间省略 ……
Processing dependencies for setuptools==33.1.1
Finished processing dependencies for setuptools==33.1.1
安装 pip
]# easy_install pip