不過想用方便點的,所以安裝requests模組,官網是Python Module - Requests
#安裝requests ref: http://docs.python-requests.org/en/v1.0.0/community/out-there/ $ yum install python-requests oaded plugins: fastestmirror, replace Setting up Install Process Determining fastest mirrors epel/metalink | 3.9 kB 00:00 * base: centos.cs.nctu.edu.tw * epel: ftp.cuhk.edu.hk * extras: centos.cs.nctu.edu.tw * updates: centos.cs.nctu.edu.tw * webtatic: sp.repo.webtatic.com base | 3.7 kB 00:00 dag | 1.9 kB 00:00 epel | 4.3 kB 00:00 epel/primary_db | 5.9 MB 00:01 extras | 3.4 kB 00:00 extras/primary_db | 37 kB 00:00 kbs-CentOS-Misc | 1.9 kB 00:00 updates | 3.4 kB 00:00 updates/primary_db | 4.6 MB 00:00 webtatic | 3.6 kB 00:00 webtatic/primary_db | 191 kB 00:00 Resolving Dependencies --> Running transaction check ---> Package python-requests.noarch 0:2.6.0-3.el6 will be installed --> Processing Dependency: python-urllib3 >= 1.10.2-1 for package: python-requests-2.6.0-3.el6.noarch ............ ............ Dependencies Resolved ==================================================================================================== Package Arch Version Repository Size ==================================================================================================== Installing: python-requests noarch 2.6.0-3.el6 base 95 k Installing for dependencies: python-backports x86_64 1.0-5.el6 base 5.5 k python-backports-ssl_match_hostname noarch 3.4.0.2-4.el6.centos extras 13 k python-chardet noarch 2.2.1-1.el6 base 230 k python-six noarch 1.9.0-2.el6 base 28 k python-urllib3 noarch 1.10.2-1.el6 base 101 k Transaction Summary ==================================================================================================== Install 6 Package(s) Total download size: 472 k Installed size: 1.9 M Is this ok [y/N]: y ............ ............ Complete!這樣就完成了。
Excel的話則是選openpyxl,不過這個套件只支援Excel 2007以後的文件,也要注意版本,如openpyxl 1.x支援Excel 2007,但openpyxl 2.4.0是支援Excel 2010,以及Python至少要2.6以後的版本。
先使用下列指令確認Python版本
$ python -V Python 2.6.6
下載setuptools(若沒安裝,在安裝openpyxl會出現找不到setuptools套件的訊息)
$ wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz $ tar -xvf setuptools-1.4.2.tar.gz $ cd setuptools-1.4.2 $ python setup.py install #安裝動作必須是root權限
再來就可以安裝openpyxl 2.4.0
$ wget https://pypi.python.org/packages/source/o/openpyxl/openpyxl-2.4.0-a1.tar.gz $ tar -xvf openpyxl-2.4.0-a1.tar.gz $ cd openpyxl-2.4.0-a1 $ python setup.py install #安裝動作必須是root權限
這樣兩個都可以用了
參考網址:
Python Network Programming
Python Module - Requests
openpyxl 2.4.0-a1
How To Set Up Python 2.7.6 and 3.3.3 on CentOS 6.4
沒有留言:
張貼留言