1. 程式人生 > >centos6.8搭建python2.7.13開發環境

centos6.8搭建python2.7.13開發環境

python 2.7

操作系統版本:CentOS release 6.8
openssl版本:OpenSSL 1.0.1e-fips
python版本:python2.7.13


第一步.安裝python2.7.13.tgz

[root@localhost home]wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
[root@localhost home]yum install -y openssl openssl-devel
[root@localhost home]tar -xf Python-2.7.13.tgz && cd Python-2.7.13

[root@localhost Python-2.7.13]./configure --prefix=/usr/local/python2.7.13
[root@localhost Python-2.7.13]sed -i ‘/#_socket socketmodule.c/a_socket socketmodule.c timemodule.c‘ Modules/Setup
[root@localhost Python-2.7.13]sed -i ‘/#_ssl _ssl.c/i_ssl _ssl.c -DUSE_SSL -I\$(SSL)\/include -I\$(SSL)\/include\/openssl -L\$(SSL)\/lib -lssl -lcrypto‘ Modules/Setup

[root@localhost Python-2.7.13]make && make install

[root@localhost Python-2.7.13]mv /usr/bin/python /usr/bin/python-2.6.6
[root@localhost Python-2.7.13]ln -s /usr/local/python2.7.13/bin/python2.7 /usr/bin/python

因為yum是依賴python的,所以這裏我們修改了默認的python,就要要修改yum,讓其運行指向舊的版本:

[root@localhost Python-2.7.13]sed -i "s/^#!\/usr\/bin\/python$/#!\/usr\/bin\/python-2.6.6/" /usr/bin/yum


第二步.安裝setuptools
[root@localhost Python-2.7.13]cd /home/
[root@localhost home]wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
[root@localhost home]tar -xf setuptools-0.6c11.tar.gz && cd setuptools-0.6c11
[root@localhost setuptools-0.6c11]python setup.py build && python setup.py install


第三步.安裝pip
pip 安裝:
[root@localhost setuptools-0.6c11]cd /home/
[root@localhost home]wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
[root@localhost home]tar -xf pip-9.0.1.tar.gz && cd pip-9.0.1
[root@localhost pip-9.0.1]python setup.py install
[root@localhost pip-9.0.1]ln -s /usr/local/python2.7.13/bin/pip /usr/bin/pip

1.pip安裝包
語法:
pip install 安裝包名稱

2.pip查看已安裝的包
pip list --format=columns
pip show --files 安裝包名稱
#pip show --files pytz

3.pip檢查哪些包需要更新
pip list --outdated --format=columns

4.pip升級包
pip install --upgrade 安裝包名稱

5.pip卸載包
pip uninstall 安裝包名稱


第四步.安裝distribute nose virtualenv
1安裝distribute
[root@localhost pip-9.0.1]pip install distribute

2.安裝nose
[root@localhost pip-9.0.1]pip install nose

3.安裝virtualenv
[root@localhost pip-9.0.1]pip install virtualenv

4.安裝web框架
[root@localhost pip-9.0.1]pip install lpthw.web


第五步:創造python項目
1.創建python骨架
[root@localhost home]mkdir projects && cd projects/
[root@localhost projects]mkdir gothonweb && cd gothonweb && mkdir bin gothonweb tests docs templates
[root@localhost gothonweb]touch gothonweb/init.py
[root@localhost gothonweb]touch tests/init.py

2.在創建 app.py文件
vim bin/app.py加入以下內容

import web
urls = (
‘/‘, ‘index‘
)
app = web.application(urls, globals())
class index:
def GET(self):
greeting = "Hello World"
return greeting
if name == "main":
app.run()

執行命令 python bin/app.py(不要切換目錄執行)
註意:在所有的 python 項目中,你都不需要進到底層目錄去運行東西。你應該停留在最上層目錄運行,這樣才能保證所有的模組和文件能被正常訪問到。

出現以下情況即為成功

centos6.8搭建python2.7.13開發環境