Linux(Centos)下搭建Scrapy环境

tech2022-07-31  170

1..Linux下安装Python3.6和pip

CentOS 7上默认安装的python版本是2.7.5,系统自带的旧版本python被系统很多其他软件环境依赖,因此不能卸载原Python,直接选择Python3.6.5进行全新安装。

1.安装Python3.6可能使用的依赖

yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ 

2.安装Python3.6.5

1、下载python3.6.5的Linux安装包https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

或者使用wget下载,到Python官网找到下载路径

wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

(前提是安装好 wget 。安装wget,输入命令:yum -y install wget)

yum方法安装的,可以用 yum list installed 查找,如果是查找指定包,用 yum list installed | grep "软件名或者包名"

(也可以本地下载好,通过Xshell传输到unix)

2、使用root权限打开终端,进行解压缩操作

tar -zxvf Python-3.6.5.tgz

解压缩时如果未指定解压缩目录,解压缩完成后,我们可以在当前目录下看到Python-3.6.5

将目录进行重命名

mv Python-3.6.5 python3.6

4.进入解压后的目录,编译安装。 # cd Python-3.6 # ./configure --prefix=/usr/local/python3 先 make 再 make install 5.建立python3的软链( ln [参数][源文件或目录][目标文件或目录],软链接,以路径的形式存在。类似于Windows操作系统中的快捷方式) # ln -s /usr/local/python3/bin/python3 /usr/bin/python3

(python3实际的安装目录是/usr/local/ 。/usr/bin/相当于是快捷方式目录)

6.并将/usr/local/python3/bin加入PATH # vi ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/usr/local/python3/bin export PATH   按ESC,输入:wq回车退出。   修改完记得执行行下面的命令,让上一步的修改生效: # source ~/.bash_profile (很重要)   检查Python3及pip3是否正常可用:

2、安装Scrapy

由于scrapy相关依赖较多,先安装依赖

pip3 install w3lib

pip3 install twisted

(注意:因为很多国外网站访问缓慢,建议用豆瓣镜像

安装twisted:pip3 install -i https://pypi.doubanio.com/simple/ twisted)

pip3 install lxml

最后安装 pip3 install scrapy即可

 

最新回复(0)