win环境配置scrapy

最近在学习《精通Python爬虫框架Scrapy - 2018》首要的就是搭建好Scrapy,这个书里推荐使用虚拟环境Vagrant完成。我一开始打算在Ubuntu里搞,但是我Ubuntu自带的python3.4版本太低,提示我pip需要3.5以上,然后我删了Py3.4发现好多系统组件都没了,就重装了一下Ubuntu。后来还是觉得win里搭建好一些。

https://blog.csdn.net/qq_32216809/article/details/86347926?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

升级自带Py可以看下这个贴子,感觉可行。

1、通常在win里安装完Py之后,就已经有了pip了,可以在cmd命令行里输入pip show pip看下

2、如果不是最新版可以升级一下:python -m pip install --upgrade pip

但是由于国内网络原因,通过这种方式进行下载经常出现中断或者低速问题。这样的话,改一下源就可以解决(我是从Ubuntu里更新软件源想到的,换成国内的镜像)

 1 # -*- coding: utf-8 -*-
 2 """
 3 Python3 --> 解决PIP下载安装速度慢
 4 """
 5 import os
 6  
 7 PATH = f"C:{os.environ['HOMEPATH']}\\pip"
 8 FILE = 'pip.ini'
 9  
10 # 国内源:
11 # 新版ubuntu要求使用https源,要注意。
12 DICTURL = {
13     '清华': 'https://pypi.tuna.tsinghua.edu.cn/simple/',
14     '阿里云': 'http://mirrors.aliyun.com/pypi/simple/',
15     '中国科技大学': 'https://pypi.mirrors.ustc.edu.cn/simple/',
16     '华中理工大学': 'http://pypi.hustunique.com/',
17     '山东理工大学': 'http://pypi.sdutlinux.org/',
18     '豆瓣': 'http://pypi.douban.com/simple/'
19 }
20  
21 # pip.ini 配置文件内容
22 INFO = f"""[global]
23 index-url = {DICTURL['清华']}
24 [install]
25 trusted-host=mirrors.aliyun.com"""
26  
27 # 判断pip文件夹是否存在,存在跳过,不存在创建
28 if not os.path.exists(PATH):
29     os.mkdir(PATH)
30  
31 # 创建配置文件,写入内容
32 with open(os.path.join(PATH, FILE), 'w', encoding='utf-8') as f:
33     f.write(INFO)
34  
35 print(f'用户路径:{PATH}\n配置文件:{FILE}\n****创建成功!****')

保存这个代码.py,然后运行一下就成功更改pip的源了。代码出处我忘记了,感谢开源网友。

3、pip install pypiwin32 安装

4、pip install Twisted 安装,如果不行就离线安装

5、pip install scrapy 最后一步

安装需要耐心等待。

猜你喜欢

转载自www.cnblogs.com/Yuya-memeda/p/12373647.html