# 在CentOS 6上安装Python 2.7以及virtualenv环境

> 最近有遇到一个古老的CentOS 6环境安装Python 2.7并且部署virtualenv的需求，稍微整理一下笔记

维护老系统，需要升级python 2.7已更好支持pssh运行。系统python版本2.6，比较古老，但是不能直接升级，所以采用在个人HOME目录独立编译安装python 2.7，然后构建virtualenv环境运行应用。

* 编译python

```bash
PREFIX=/home/admin/huatai

wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
tar xfz Python-2.7.18.tgz
cd Python-2.7.18/
./configure --prefix=$PREFIX
make
make install
```

* 设置环境变量

```bash
echo "export PATH=$HOME/huatai/bin:$PATH" >> $PREFIX/profile
. $PREFIX/profile
```

* 安装virtualenv

```bash
pip2 install virtualenv
```

* 创建Python virtualenv环境

```bash
cd /home/admin/huatai.huang
virtualenv -p /home/admin/huatai.huang/bin/python2.7 venv2
. venv2/bin/activate
```

* 安装pssh

```bash
pip install pssh
```

现在就可以顺利使用升级后的Python 2.7以及通过virtualenv工作。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://huataihuang.gitbook.io/cloud-atlas-draft/develop/python/startup/install_python_2.7_and_virtualenv_in_centos_6.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
