已安装Python 3.6.5,但该文件采用python 2.7作为默认文件

时间:2018-06-22 13:28:30

标签: python scrapy

当我尝试获取默认的python版本时显示3.6,但是当我尝试运行其代码在python 2.7中运行时...我使用了scrapy crawl cablo来使文件运行 还安装了ABC抽象方法

Traceback (most recent call last):
  File "/usr/local/bin/scrapy", line 11, in <module>    
sys.exit(execute())
  File "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py", line 149, in execute
cmd.crawler_process = CrawlerProcess(settings)
  File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 249, in _init_
super(CrawlerProcess, self).__init__(settings)
  File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 137, in _init_
self.spider_loader = _get_spider_loader(settings)
  File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 336, in _get_spider_loader
return loader_cls.from_settings(settings.frozencopy())
  File "/usr/local/lib/python2.7/dist-packages/scrapy/spiderloader.py", line 61, in from_settings
return cls(settings)
  File "/usr/local/lib/python2.7/dist-packages/scrapy/spiderloader.py", line 25, in _init_
self._load_all_spiders()
  File "/usr/local/lib/python2.7/dist-packages/scrapy/spiderloader.py", line 47, in _load_all_spiders
for module in walk_modules(name):
  File "/usr/local/lib/python2.7/dist-packages/scrapy/utils/misc.py", line 71, in walk_modules
submod = import_module(fullpath)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
  File "/home/megha/Downloads/Data_scuff/Data_scuff/spiders/cablo.py", line 11, in <module>

from abc import ABC, abstractmethod

ImportError:无法导入姓名ABC

enter image description here

1 个答案:

答案 0 :(得分:0)

ABC python 3:这是我用于2.7和3.5的代码片段。如果您不关心2.7,可以跳过六个步骤

import six
from abc import ABCMeta, abstractmethod


@six.add_metaclass(ABCMeta)
class BaseRequest(object):
    """baseclass for request classes."""

    @abstractmethod
    def __init__(self):
        self._data = dict()