centos 安装配置python虚拟环境、pip
centos 安装配置python虚拟环境、pip
1.安装pip包安装工具
# 系统默认源没有pip安装包
[root@localhost python]# yum install python-pip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: repos.dfw.quadranet.com
* extras: sjc.edge.kernel.org
* updates: mirror.hmc.edu
No package python-pip available.
Error: Nothing to do
# 安装epel源
[root@localhost python]# yum -y install epel-release
# 再次安装
[root@localhost python]# yum install python-pip
.....
Installed:
python2-pip.noarch 0:8.1.2-6.el7
Complete!
# 安装成功
2.安装virtualenv
2.1 使用pip安装virtualenv
[root@localhost python]# pip install virtualenv
如果提示You should consider upgrading via the 'pip install --upgrade pip' command.
就执行pip install --upgrade pip更新后再安装即可
2.2 使用yum安装virtualenv
[root@localhost python]# yum install python-virtualenv
3.配置python虚拟环境
# 创建名为env1的虚拟环境
[root@localhost python]# virtualenv env1
# 进入虚拟环境
[root@localhost python]# source env1/bin/activate
(env1) [root@localhost python]#
# 退出虚拟环境
(env1) [root@localhost python]# deactivate
[root@localhost python]#