在CentOs6.5下安裝Python2.7.6和Scrapy
總在網上看你們的安裝教程,這回本身也貢獻一份!!!css
和民航大學合做項目,去給人家裝環境,連簡單的Scrapy都沒裝上,雖然有對方硬件設施坑爹的因素,但主要仍是本身準備不充分。html
一份好的安裝文檔應該是能夠完美重現的。python
因此作了下面這份:sql
我按照這套方法連着重裝了四次,若是各位直接複製命令,應該是一點問題都沒有。安裝成功的樣子見那兩張截圖。bootstrap
對了,確保電腦能上網,鼠標能用,哈哈vim
1.#su – rootpython2.7
2.#yum install gcc zlib-devel bzip2-devel openssl-devel ncurses-devel libffi-devel libxslt-devel libxml2-devel sqlite-develscrapy
3.#cd /usride
4.安裝Python
#wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
#xz -d Python-2.7.6.tar.xz
#tar xvf Python-2.7.6.tar
#cd Python-2.7.6
#./configurepost
#vim Modules/Setup
找到下面這句,去掉註釋
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
編譯安裝:make & make install
5.修改Python連接
#/usr/local/bin/python2.7 -V
#mv /usr/bin/python /usr/bin/python.bak
# ln -s /usr/local/bin/python2.7 /usr/bin/python
6.#vim /usr/bin/yum
在打開的文件裏的頭一行,也就是指定python環境的那行代碼,修改爲:
#!/usr/bin/python2.6
7.#wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
#python ez_setup.py
8.#wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
#python get-pip.py
9.#pip install scrapy
10.#scrapy
11.創建測試腳本
12.# cat > myspider.py <<EOF
from scrapy import Spider, Item, Field
class Post(Item):
title = Field()
class BlogSpider(Spider):
name, start_urls = 'blogspider', ['http://www.cnblogs.com/rwxwsblog/']
def parse(self, response):
return [Post(title=e.extract()) for e in response.css("h2 a::text")]
EOF
13.試建工程
scrapy startproject tutorial