苦逼的前夜
昨晚很辛苦,搞到晚上快兩點(diǎn)侧巨,最后還是沒(méi)有把python3下的scrapy框架安裝起來(lái),后面還把yum這玩意給弄壞了鞭达,一直找不到命令司忱。今天早上又自己弄了快一上午,又求助@函兮畴蹭,弄了快一個(gè)中午坦仍,最后無(wú)奈還是沒(méi)有弄好yum跟python這玩意,最后還是放棄治療了撮胧。真的是什么招桨踪,什么損招都用完了,最后也沒(méi)折了芹啥,直接報(bào)告老大去锻离,然后把阿里云的centos7實(shí)例重新磁盤回滾了一下铺峭。
正確的安裝姿勢(shì)
這個(gè)不多廢話,如果你是直接接手過(guò)來(lái)一個(gè)centos7的實(shí)例鏡像汽纠,當(dāng)然包括騰訊云或者阿里云上面的卫键,只要按照下面的步驟進(jìn)行安裝,沒(méi)有裝不上虱朵,只有裝得舒服莉炉,不到半小時(shí),完完整整的裝好Python3碴犬,裝好Python3下的scrapy框架
步驟
前言:不用改掉系統(tǒng)python2.7 絮宁,原來(lái)是python2.7,我們還進(jìn)行python2.7的保留
1.編譯前準(zhǔn)備其他庫(kù)的安裝(使用sudo命令)
(1)
[root@hadron ~]# yum -y groupinstall "Development tools"
(2)
[root@hadron ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
(2)這里有點(diǎn)長(zhǎng)服协,一定要復(fù)制完整了再進(jìn)行回車绍昂,中途可能會(huì)報(bào)錯(cuò),提示會(huì)有:--skip-broken
可以使用命令:
[root@hadron ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel --skip-broken
2 . 到這里我們就可以進(jìn)行python3.5的源碼下載了
(1)使用wget命令:
[root@hadron ~]# wget https://www.python.org/ftp/python/3.5.5/Python-3.5.5.tgz
(2)然后解壓縮偿荷,進(jìn)入根目錄
[root@hadron ~]# tar -zxvf Python-3.5.5.tgz
[root@hadron ~]# cd Python-3.5.5/
(3)python3.5進(jìn)行編譯安裝
[root@hadron ~]# ./configure --prefix=/usr/local/python3
[root@hadron ~]# make && make install
(4)創(chuàng)建Python3窘游,pip3的軟鏈接
[root@hadron ~]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@hadron ~]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
(5)驗(yàn)證Python3 和pip3 是否安裝成功
[root@hadron ~]# python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
[root@hadron ~]# python3
Python 3.5.5 (default, Feb 27 2018, 09:28:49)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
[root@hadron ~]#
[root@hadron ~]# pip3 --version
pip 9.0.1 from /usr/local/python3/lib/python3.5/site-packages (python 3.5)
這里我們可以看到默認(rèn)的python還是系統(tǒng)自帶的python2.7,而python3就是我們解壓的python3.5.5了跳纳,pip3 也是python3.5下的pip了忍饰。
上面我們已經(jīng)把python3跟pip3安裝好了,接下來(lái)寺庄,我們進(jìn)行Python3下的Scrapy框架安裝
3 安裝Scrapy爬蟲(chóng)框架
(1)安裝Scrapy
[root@hadron ~]# pip3 install scrapy
Collecting scrapy
Downloading Scrapy-1.5.0-py2.py3-none-any.whl (251kB)
100% |████████████████████████████████| 256kB 1.1MB/s
Requirement already satisfied: lxml in /usr/local/python3/lib/python3.5/site-packages (from scrapy)
Collecting PyDispatcher>=2.0.5 (from scrapy)
Downloading PyDispatcher-2.0.5.tar.gz
....
....
Collecting pycparser (from cffi>=1.7; platform_python_implementation != "PyPy"->cryptography>=2.1.4->pyOpenSSL->scrapy)
Downloading pycparser-2.18.tar.gz (245kB)
100% |████████████████████████████████| 256kB 339kB/s
Installing collected packages: PyDispatcher, zope.interface, constantly, incremental, six, attrs, Automat, hyperlink, Twisted, cssselect, w3lib, parsel, asn1crypto, pycparser, cffi, cryptography, pyOpenSSL, pyasn1, pyasn1-modules, service-identity, queuelib, scrapy
Running setup.py install for PyDispatcher ... done
Running setup.py install for Twisted ... done
Running setup.py install for pycparser ... done
Successfully installed Automat-0.6.0 PyDispatcher-2.0.5 Twisted-17.9.0 asn1crypto-0.24.0 attrs-17.4.0 cffi-1.11.4 constantly-15.1.0 cryptography-2.1.4 cssselect-1.0.3 hyperlink-18.0.0 incremental-17.5.0 parsel-1.4.0 pyOpenSSL-17.5.0 pyasn1-0.4.2 pyasn1-modules-0.2.1 pycparser-2.18 queuelib-1.4.2 scrapy-1.5.0 service-identity-17.0.0 six-1.11.0 w3lib-1.19.0 zope.interface-4.4.3
[root@hadron ~]#
在這里進(jìn)行安裝的時(shí)候艾蓝,我們可能會(huì)出現(xiàn)一串的報(bào)紅,一串的報(bào)紅铣揉。
出現(xiàn)報(bào)紅不要緊饶深,我們多試幾次pip3 install scrapy 就行了
(2)網(wǎng)絡(luò)好的話,試下不超過(guò)5次逛拱,應(yīng)該就會(huì)出現(xiàn)下面安裝成功的界面
(3)上面的圖也是驗(yàn)證Scrapy框架安裝成功的界面敌厘,因?yàn)槲覀冞M(jìn)行了import scrapy沒(méi)有進(jìn)行報(bào)錯(cuò)。
(4)創(chuàng)建Scrapy軟鏈接
[root@hadron ~]# ln -s /usr/local/python3/bin/scrapy /usr/bin/scrapy
(5)驗(yàn)證Scrapy軟鏈接
[root@hadron ~]# scrapy -v
Scrapy 1.5.0 - no active project
上面就是整個(gè)Python3下Scrapy框架的安裝步驟過(guò)程朽合,基本上沒(méi)有bug俱两。上面就是我對(duì)這不到半小時(shí)的安裝比對(duì)昨天一個(gè)晚上的安裝的心得體會(huì),搜到好的文章曹步,然后再繼續(xù)你的下一步宪彩。