mac python3.8怎样安装scrapy_python数据抓取环境框架scrapy环境搭建,mac安装scrapy ,pip3, pymysql,更新python版本,设置python默认版本...

本文介绍了在Mac系统中如何安装Python3.8,包括升级Python、设置默认版本,安装pip3,以及解决在安装Scrapy过程中遇到的Twisted依赖错误、pymysql安装和Linux服务器部署时的openssl版本问题。
摘要由CSDN通过智能技术生成

安装pip3

MAC默认python版本是python2.7,然后python2.7即将成为历史,安装python3相关包需要先安装pip3

安装get-pip.pycurl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

下载成功后执行python3 get-pip.py

可以通过  pip3 -V 来查看是否成功

mac切换默认的python为python3

打开终端输入open ~/.bash_profile

添加python3路径PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"

export PATH

保存后,在终端输入命令,添加python别名alias python="/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.6"

更新环境变量source .bash_profile

然后在输入python可以看到已经切换到了python3

mac安装scrapypip3 install Scrapy

第一次安装提示错误信息

Complete output from command python setup.py egg_info:

更新setuptoolspip3 install --upgrade setuptools

然后重新安装scrapypip3 install Scrapy

漫长的等待,在安装到Twisted时发生错误

Collecting Twisted>=13.1.0 (from Scrapy)

ERROR: Complete output from command python setup.py egg_info:

ERROR: Download error on https://pypi.org/simple/incremental/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:598) -- Some packages may not be found!

试了网上办法,失败,决定升级python版本试试

升级pythonbrew install python3

升级到python3.7.3后,重新安装scrapypip3 install Scrapy

ok成功

安装

安装数据库插件pymysqlpip3 install PyMySQL

linux服务器部署遇到的问题汇总

安装python最新版本3.7.3wget  https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz

tar -zxvf Python-3.7.3.tgz

cd Python-3.7.3

./configure

make && make install

使用pip3  install Scrapy报错

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Collecting virtualenv

原因:系统版本centos6.5,其中openssl的版本为OpenSSL 1.0.1e-fips 11 Feb 2013,而python3.7需要的openssl的版本为1.0.2或者1.1.x,需要对openssl进行升级,并重新编译python3.7.0。yum 安装的openssl 版本都比较低。

升级openssl

# 1.下载openssl

wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz

tar -zxvf openssl-1.1.1a.tar.gz

cd openssl-1.1.1a

# 2.编译安装

./config --prefix=/usr/local/openssl no-zlib #不需要zlib

make

make install

# 3.备份原配置

mv /usr/bin/openssl /usr/bin/openssl.bak

mv /usr/include/openssl/ /usr/include/openssl.bak

# 4.新版配置

ln -s /usr/local/openssl/include/openssl /usr/include/openssl

ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so

ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

# 5.修改系统配置

## 写入openssl库文件的搜索路径

echo "/usr/local/openssl/lib" >> /etc/ld.so.conf

## 使修改后的/etc/ld.so.conf生效

ldconfig -v

# 6.查看openssl版本

openssl version

# 7.重新安装python./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl

make

make install

我这边重试仍然报错,最后使用 /usr/local/python3/bin/pip3 install scrapy,安装scrapy成功

运行scrapy命令报错

运行scrapy crawl spider-name,报错

No module named '_sqlite3'

安装sqlite3yum install sqlite-devel

部署

通过脚本执行某个爬虫,新建scrapy.sh#! /bin/sh

cd /projectdir  #进入你的项目目录

nohup scrapy crawl spider_name &

为脚本添加执行权限

chomd +x ./scrapy.sh

设置定时任务,执行这个脚本即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值