windows下使用virtualenv安装scrapy

本文档详细介绍了在Windows系统中,如何在Python 2.7环境中使用virtualenv和virtualenvwrapper-win创建独立的Python环境,并安装Scrapy。首先安装Python 2.7和3.4,接着安装virtualenvwrapper-win。通过设置WORKON_HOME环境变量,创建Python 2.7的虚拟环境,并解决在安装Scrapy过程中遇到的服务身份验证模块和服务标识模块缺失问题。最后解决了因缺少pywin32模块导致的Scrapy shell启动错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

系统为win8中文版,本来想用最新版python3.4,但是scrapy只支持python 2.7, 所以涉及到python2 和python3共存的问题。在网上查了下,大多数只是python 的版本切换的方法,我想要的是python2 和python3 都有各自的pip、各类包什么的,各自独立,网上推荐是使用虚拟环境。

(关于我想要的python2 和python3共存的哪种方式另说)

windows下python3.4 的虚拟环境(使用virtualenvwrapper-win)安装步骤:

1、安装好python3.4和python2.7.8

2、pip install virtualenvwrapper-win  安装virtualenvwrapper-win

3、设置一个系统变量WORKON_HOME字段,路径设定为你喜好的处所,建议不要用中文路径,不要有空格路径

4、尝试建立虚拟目录,mkvirtualenv VirtualenvName。但是出现错误

Using base prefix 'C:\\Python34'
New python executable in moveit\Scripts\python.exe
Failed to import the site module
Traceback (most recent call last):
  File "C:\Work\ICG\.envs\moveit\lib\site.py", line 67, in <module>
    import os
  File "C:\Work\ICG\.envs\moveit\lib\os.py", line 614, in <module>
    from _collections_abc import MutableMapping
ImportError: No module named '_collections_abc'
ERROR: The executable moveit\Scripts\python.exe is not functioning
ERROR: It thinks sys.prefix is 'c:\\work\\icg\\.envs' (should be 'c:\\work\\icg\
\.envs\\moveit')
ERROR: virtualenv is not compatible with this system or executable
Note: some Windows users have reported this error when they installed Python for
 "Only this user" or have multiple versions of Python installed. Copying the app
ropriate PythonXX.dll to the virtualenv Scripts/ directory may fix this problem.
解决方法:先pip uninstall virtualenv,然后再重新安装最新版pip install virtualenv==1.11.1

5、mkvirtualenv -p D:\Python27\python.exe VirtualenvName 成功  -p D:\Python27\python.exe是使虚拟目录中的python版本为我系统中安装的2.7版(这是由于scrapy只支持python2.7)

6、workon VirtualenvName  切换到VirtualenvName 虚拟目录

7、安装scrapy  pip install scrapy

8、尝试启动scrapy,但是有warning:
:0: UserWarning: You do not have a working installation of the service_identity
module: 'No module named service_identity'.  Please install it from <https://pyp
i.python.org/pypi/service_identity> and make sure all of its dependencies are sa
tisfied.  Without the service_identity module and a recent enough pyOpenSSL to s
upport it, Twisted can perform only rudimentary TLS client hostname verification
.  Many valid certificate/hostname mappings may be rejected.
于是执行:pip install.py service_identity,一大堆看起来就是缺少了一个模块,完成再次启动scrapy,成功!

9、启动scrapy shell,报错一大堆,比如 scrapy shell ”www.baidu.com“

找到下面这串:
    raise ImportError("Error loading object '%s': %s" % (path, e))
ImportError: Error loading object 'scrapy.core.downloader.handlers.s3.S3Download
Handler': No module named win32api
这说明缺少模块win32api,需要安装pywin32

解决办法:下载pywin32-219.win-amd64-py2.7.exe(可以在http://sourceforge.net/projects/pywin32/files/pywin32/下载),这个文件的路径避免中文路径和空格,然后再虚拟目录里easy_install"C:\Path\To\Downloads\pywin32-219.win32-py3.4.exe"

搞定!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值