gpt4 book ai didi

python 和碎片 : Issue with Scrapy version

转载 作者:太空狗 更新时间:2023-10-30 01:01:10 25 4
gpt4 key购买 nike

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

pip install scrapy

然后我按照示例项目的初始化,尝试执行example 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

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

2015-02-23 10:23:42+0100 [scrapy] INFO: Scrapy 0.14.4 started (bot: example)
  1. 我尝试卸载并重新安装
  2. 我也尝试更新 pip,卸载 scrapy 并重新安装
  3. 我尝试使用 apt-get 安装它

  • 为什么如果我安装了最新版本 (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)

如果我按照@aberna 的建议执行scrapy version,我得到:

Scrapy 0.14.4

最佳答案

当时我遇到了类似的问题,这是因为 Ubuntu 包与 pip 包混淆了。

当我使用 pip 安装 Scrapy 并尝试运行它时,scrapy 说这个包缺少一些依赖项,然后我安装了 Scrapy使用 apt-get 并且我搞砸了包版本。

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

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

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

编辑

您可以在 Scrapy 文档中阅读:

python-scrapy is a different package provided by official debian repositories, it’s very outdated and it isn’t supported by Scrapy team.

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

  1. Import the GPG key used to sign Scrapy packages into APT keyring:

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

  2. Create /etc/apt/sources.list.d/scrapy.list file using the following command:

    echo 'deb http://archive.scrapy.org/ubuntu scrapy main' | sudo tee /etc/apt/sources.list.d/scrapy.list

3.Update package lists and install the scrapy-0.24 package:

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

Check Here: Scrapy on Ubuntu

关于 python 和碎片 : Issue with Scrapy version,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28670554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com