Python& Scrapy:Scrapy版本的问题

时间:2015-02-23 09:31:02

标签: python scrapy pip

我正在使用 Ubuntu 14.04 x64 ,我已按照 Scrapy 文档使用 pip 安装软件包:

pip install scrapy

然后我跟着示例项目的初始化并尝试执行示例spider

scrapy crawl example

我收到此错误:

2015-02-23 10:23:42+0100 [scrapy] INFO: Scrapy 0.14.4 started (bot: example)
2015-02-23 10:23:42+0100 [scrapy] DEBUG: Enabled extensions: LogStats, TelnetConsole, CloseSpider, WebService, CoreStats, MemoryUsage, SpiderState
Traceback (most recent call last):
  File "/usr/local/bin/scrapy", line 11, in <module>
    sys.exit(execute())
  File "/usr/lib/python2.7/dist-packages/scrapy/cmdline.py", line 132, in execute
    _run_print_help(parser, _run_command, cmd, args, opts)
  File "/usr/lib/python2.7/dist-packages/scrapy/cmdline.py", line 97, in _run_print_help
    func(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/scrapy/cmdline.py", line 139, in _run_command
    cmd.run(args, opts)
  File "/usr/lib/python2.7/dist-packages/scrapy/commands/crawl.py", line 43, in run
    spider = self.crawler.spiders.create(spname, **opts.spargs)
  File "/usr/lib/python2.7/dist-packages/scrapy/command.py", line 34, in crawler
    self._crawler.configure()
  File "/usr/lib/python2.7/dist-packages/scrapy/crawler.py", line 36, in configure
    self.spiders = spman_cls.from_crawler(self)
  File "/usr/lib/python2.7/dist-packages/scrapy/spidermanager.py", line 37, in from_crawler
    return cls.from_settings(crawler.settings)
  File "/usr/lib/python2.7/dist-packages/scrapy/spidermanager.py", line 33, in from_settings
    return cls(settings.getlist('SPIDER_MODULES'))
  File "/usr/lib/python2.7/dist-packages/scrapy/spidermanager.py", line 23, in __init__
    for module in walk_modules(name):
  File "/usr/lib/python2.7/dist-packages/scrapy/utils/misc.py", line 65, in walk_modules
    submod = __import__(fullpath, {}, {}, [''])
  File "/home/alvaro/vagrantenvs/example/example/spiders/example_spider.py", line 3, in <module>
    class ExampleSpider(scrapy.Spider):
AttributeError: 'module' object has no attribute 'Spider'

我使用pip freeze | grep 'Scrapy'检查了 Scrapy 的已安装版本,我得到了:

Scrapy==0.24.4

但正如您在traceback错误中看到的那样:

2015-02-23 10:23:42+0100 [scrapy] INFO: Scrapy 0.14.4 started (bot: example)
  1. 我尝试卸载并重新安装
  2. 我还尝试更新pip,卸载scrapy并重新安装
  3. 我尝试使用 apt-get
  4. 安装它
    • 为什么如果我安装了最新版本(0.24.4),它似乎正在执行0.14.4?
    • 这个问题与Scrapy,Pip或两者有关吗?

    编辑:

    这是文件example_spider.py:

    import scrapy
    
    class ExampleSpider(scrapy.Spider):
        name = "example"
        allowed_domains = ["dmoz.org"]
        start_urls = [
            "http://www.dmoz.org/Computers/Programming/Languages/Python/Books/",
            "http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/"
        ]
    
        def parse(self, response):
            filename = response.url.split("/")[-2]
            with open(filename, 'wb') as f:
                f.write(response.body)
    

    如果我执行scrapy version为@aberna sugested我得到了:

    Scrapy 0.14.4
    

1 个答案:

答案 0 :(得分:6)

当时我遇到了类似的问题,原因是 Ubuntu 包正在弄乱 pip 包。

当我使用 pip 安装Scrapy并尝试运行它时, scrapy 表示该软件包缺少某些依赖项,然后我安装了 Scrapy 使用apt-get,我在那里搞砸了软件包版本。

我建议您从 Ubuntu Pip 中删除这两个软件包,然后仅使用pip重新安装:

apt-get remove --purge python-scrapy
pip uninstall scrapy

完成这些操作后,您可以使用pip再次安装,然后如果您执行scrapy version,您应该获得最新版本的响应,在您的情况下应该 0.24 0.4

修改

您可以在Scrapy文档中阅读:

  

python-scrapy是官方debian存储库提供的一个不同的包,它已经过时了,Scrapy团队不支持它。

要在Ubuntu中安装Scrapy,他们会说:

  
      
  1. 将用于签署Scrapy软件包的GPG密钥导入APT密钥环:

         

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 627220E7

  2.   
  3. 使用。创建/etc/apt/sources.list.d/scrapy.list文件   以下命令:

         回声&#39; deb http://archive.scrapy.org/ubuntu scrapy main&#39; | sudo tee /etc/apt/sources.list.d/scrapy.list

  4.         

    3.更新软件包列表并安装scrapy-0.24软件包:

         

    sudo apt-get update&amp;&amp; sudo apt-get install scrapy-0.24

Check Here: Scrapy on Ubuntu