(1)网络配置
首先:
vim /etc/sysconfig/network-scripts/ifcfg-eno16777736
然后修改ONBOOT值:
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=8329154f-2c7c-4a44-9c3a-658f31d3ad99
DEVICE=eno16777736
ONBOOT=yes# 将no改成yes
最后重启网络服务:
[root@localhost data]# ping 'www.baidu.com'
ping: unknown host www.baidu.com
[root@localhost data]# service network restart
Restarting network (via systemctl): [ 确定 ]
[root@localhost data]# ping 'www.baidu.com'
PING www.a.shifen.com (220.181.112.244) 56(84) bytes of data.
^C64 bytes from 220.181.112.244: icmp_seq=1 ttl=128 time=27.4 ms
(2)时间配置
同步网络时间:
[root@localhost data]# yum install ntpdate
[root@localhost data]# ntpdate pool.ntp.org(3)安装gcc,g++,go
[root@localhost data]# yum -y install gcc
[root@localhost data]# yum -y install gcc-c++
[root@localhost data]# yum -y install gcc-go(4)安装pip
1、首先检查linux有没有安装python-pip包,直接执行 yum install python-pip
[root@localhost data]# yum install python-pip
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.aliyun.com
没有可用软件包 python-pip。
错误:无须任何处理
2、没有python-pip包就执行命令 yum -y install epel-release
[root@localhost data]# yum -y install epel-release
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 epel-release.noarch.0.7-9 将被 安装
--> 解决依赖关系完成
依赖关系解决
===================================================================================================================================================================================================
Package 架构 版本 源 大小
===================================================================================================================================================================================================
正在安装:
epel-release noarch 7-9 extras 14 k
事务概要
===================================================================================================================================================================================================
安装 1 软件包
总下载量:14 k
安装大小:24 k
Downloading packages:
epel-release-7-9.noarch.rpm | 14 kB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : epel-release-7-9.noarch 1/1
验证中 : epel-release-7-9.noarch 1/1
已安装:
epel-release.noarch 0:7-9
完毕!3、执行成功之后,再次执行yum install python-pip
[root@localhost data]# yum install python-pip
已加载插件:fastestmirror, langpacks
epel/x86_64/metalink | 6.7 kB 00:00:00
epel | 4.7 kB 00:00:00
(1/3): epel/x86_64/group_gz | 266 kB 00:00:03
(2/3): epel/x86_64/updateinfo | 865 kB 00:00:06
epel/x86_64/primary_db FAILED 22% [================ ] 19 B/s | 1.6 MB 86:06:36 ETA
https://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora-projects/epel/7/x86_64/repodata/d296e319c1d4642168425d74fd9dd7c58588812c456b3aaa31833c8639de11ba-primary.sqlite.bz2: [Errno 12] Timeout on https://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora-projects/epel/7/x86_64/repodata/d296e319c1d4642168425d74fd9dd7c58588812c456b3aaa31833c8639de11ba-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
(3/3): epel/x86_64/primary_db | 6.2 MB 00:00:08
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* epel: mirrors.tongji.edu.cn
* extras: mirrors.163.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 python2-pip.noarch.0.8.1.2-5.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
===================================================================================================================================================================================================
Package 架构 版本 源 大小
===================================================================================================================================================================================================
正在安装:
python2-pip noarch 8.1.2-5.el7 epel 1.7 M
事务概要
===================================================================================================================================================================================================
安装 1 软件包
总下载量:1.7 M
安装大小:7.2 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/epel/packages/python2-pip-8.1.2-5.el7.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY============================= ] 552 kB/s | 1.6 MB 00:00:00 ETA
python2-pip-8.1.2-5.el7.noarch.rpm 的公钥尚未安装
python2-pip-8.1.2-5.el7.noarch.rpm | 1.7 MB 00:00:05
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 检索密钥
导入 GPG key 0x352C64E5:
用户ID : "Fedora EPEL (7) <epel@fedoraproject.org>"
指纹 : 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
软件包 : epel-release-7-9.noarch (@extras)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : python2-pip-8.1.2-5.el7.noarch 1/1
验证中 : python2-pip-8.1.2-5.el7.noarch 1/1
已安装:
python2-pip.noarch 0:8.1.2-5.el7
完毕!4、对安装好的pip进行升级 pip install --upgrade pip
[root@localhost data]# pip install --upgrade pip
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 40kB/s
Installing collected packages: pip
Found existing installation: pip 8.1.2
Uninstalling pip-8.1.2:
Successfully uninstalled pip-8.1.2
Successfully installed pip-9.0.1
(5)安装爬虫scrapy
在安装scrapy前,必须安装python-devel,否则会出现下面的错误:
src/twisted/test/raiser.c:4:20: 致命错误:Python.h:没有那个文件或目录
#include "Python.h"
^
编译中断。
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-WRtCDy/Twisted/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-Y_62q3-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-WRtCDy/Twisted/所以应该先安装python-devel:
[root@localhost ~]# yum install python-devel
[root@localhost ~]# pip install Scrapy测试是否安装成功:
[root@localhost ~]# scrapy startproject spider出现下面错误:
Traceback (most recent call last):
File "/usr/bin/scrapy", line 7, in <module>
from scrapy.cmdline import execute
File "/usr/lib/python2.7/site-packages/scrapy/cmdline.py", line 9, in <module>
from scrapy.crawler import CrawlerProcess
File "/usr/lib/python2.7/site-packages/scrapy/crawler.py", line 7, in <module>
from twisted.internet import reactor, defer
File "/usr/lib64/python2.7/site-packages/twisted/internet/reactor.py", line 38, in <module>
from twisted.internet import default
File "/usr/lib64/python2.7/site-packages/twisted/internet/default.py", line 56, in <module>
install = _getInstallFunction(platform)
File "/usr/lib64/python2.7/site-packages/twisted/internet/default.py", line 44, in _getInstallFunction
from twisted.internet.epollreactor import install
File "/usr/lib64/python2.7/site-packages/twisted/internet/epollreactor.py", line 24, in <module>
from twisted.internet import posixbase
File "/usr/lib64/python2.7/site-packages/twisted/internet/posixbase.py", line 18, in <module>
from twisted.internet import error, udp, tcp
File "/usr/lib64/python2.7/site-packages/twisted/internet/tcp.py", line 28, in <module>
from twisted.internet._newtls import (
File "/usr/lib64/python2.7/site-packages/twisted/internet/_newtls.py", line 21, in <module>
from twisted.protocols.tls import TLSMemoryBIOFactory, TLSMemoryBIOProtocol
File "/usr/lib64/python2.7/site-packages/twisted/protocols/tls.py", line 63, in <module>
from twisted.internet._sslverify import _setAcceptableProtocols
File "/usr/lib64/python2.7/site-packages/twisted/internet/_sslverify.py", line 38, in <module>
TLSVersion.TLSv1_1: SSL.OP_NO_TLSv1_1,
AttributeError: 'module' object has no attribute 'OP_NO_TLSv1_1'原因是使用pip install Scrapy自动安装了较高版本的Twisted,版本包是Twisted-17.9.0.tar.bz2
解决办法:
查看Requirement already satisfied中对应的Twisted版本,比如是13.1.0,然后输入:
[root@localhost ~]# pip install twisted==13.1.0
[root@localhost data]# scrapy startproject spider
New Scrapy project 'spider', using template directory '/usr/lib/python2.7/site-packages/scrapy/templates/project', created in:
/data/spider
You can start your first spider with:
cd spider
scrapy genspider example example.com
(6)安装numpy,pandas
pandas需要numpy版本在1.9.0上,如果用pip install numpy安装的numpy版本号是1.7.0,不符合要求。
1、在http://jaist.dl.sourceforge.net/project/numpy/NumPy/上可以看到所有版本的numpy。
[root@localhost data]# wget http://jaist.dl.sourceforge.net/project/numpy/NumPy/1.11.2/numpy-1.11.2.tar.gz
[root@localhost data]# tar -zxvf numpy-1.11.2.tar.gz
[root@localhost data]# cd numpy-1.11.2/
[root@localhost data]# python setup.py install
# 需要重启下系统
[root@localhost data]# reboot查看numpy版本号:
[root@localhost data]# python
Python 2.7.5 (default, Aug 4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.version.version
'1.11.2'
>>>
2、安装pandas,matploatlib,scipy
[root@localhost data]# pip install pandas
[root@localhost data]# pip install matplotlib
[root@localhost ~]# pip install scipy
运行matploatlib时出现下面问题:
[root@localhost ~]# python
Python 2.7.5 (default, Aug 4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 116, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup
[backend_name], 0)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
from six.moves import tkinter as Tk
File "/usr/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
ImportError: No module named Tkinter
解决方法:
[root@localhost ~]# yum -y install tkinter
这篇博客介绍了如何在CentOS7系统中配置开发环境,包括网络设置、时间同步以及安装gcc、g++、go等开发工具。重点讲述了在安装Scrapy爬虫前需要安装python-devel以避免版本不兼容问题,同时解决了因Twisted版本过高导致的问题,以及pandas对numpy版本的要求,提供了选择合适numpy版本的方法。
853

被折叠的 条评论
为什么被折叠?



