【问题标题】:Scrapy start project ends with ImportError: No module named spidersScrapy 启动项目以 ImportError 结尾:没有名为 spiders 的模块
【发布时间】:2015-07-20 17:50:32
【问题描述】:

我用

创建了一个新环境
conda create -n scraping python=2.7

我用

激活这个环境
source activate scraping

然后我继续安装scrapy(-n 抓取似乎不再需要,但我添加它以防万一)

conda install scrapy -n scraping

我现在安装了以下内容

 % conda list
# packages in environment at /Users/alexis/anaconda3/envs/scraping:
#
cffi                      1.1.2                    py27_0
cryptography              0.9.2                    py27_0
cssselect                 0.9.1                    py27_0
enum34                    1.0.4                    py27_0
idna                      2.0                      py27_0
ipaddress                 1.0.7                    py27_0
ipython                   3.2.1                    py27_0
libxml2                   2.9.2                         0
libxslt                   1.1.28                        2
lxml                      3.4.4                    py27_0
nose                      1.3.7                    py27_0
openssl                   1.0.1k                        1
pip                       7.1.0                    py27_0
pyasn1                    0.1.7                    py27_0
pycparser                 2.14                     py27_0
pyopenssl                 0.14                     py27_0
python                    2.7.10                        0
python.app                1.2                      py27_4
queuelib                  1.2.2                    py27_0
readline                  6.2                           2
scrapy                    0.24.4                   py27_0
setuptools                18.0.1                   py27_0
six                       1.9.0                    py27_0
sqlite                    3.8.4.1                       1
tk                        8.5.18                        0
twisted                   15.2.1                   py27_0
w3lib                     1.8.1                    py27_1
zlib                      1.2.8                         0
zope.interface            4.1.2                    py27_1

(我也安装了ipython)

现在当我尝试开始一个项目时,我得到了

 % scrapy startproject megadeluxe
Traceback (most recent call last):
  File "/Users/alexis/anaconda3/envs/scraping/bin/scrapy", line 4, in     <module>
    from scrapy.cmdline import execute
  File "/Users/alexis/anaconda3/envs/scraping/lib/python2.7/site-    packages/scrapy/__init__.py", line 48, in <module>
    from scrapy.spiders import Spider
ImportError: No module named spiders

查看scraping/bin/scrapy 的内容,我看不到名为spiders.py 的文件,如果我用grep 搜索class Spider,我在任何地方都找不到这样的类。

一开始我是不是在安装 conda 时做错了什么?我安装了python 2.7,这是要求。

which openssl 返回(我觉得没问题) /Users/alexis/anaconda3/envs/scraping/bin/openssl

conda list可以看到,已经安装了lxml

我有点不知所措。


[编辑] 正如 cmets 中提到的,我没有使用最新版本的废料。这并不能解释错误,但我继续使用 pip 安装最新版本(1.0)(在撰写本文时,conda 仅安装版本 0.24)。 这样做之后,开始一个项目会吐出一些东西,以Library not loaded: libssl.1.0.0.dylib结束

在堆栈溢出时查找此链接返回给我 Cannot Set Up a Scrapy Project

Joe Hooper 给出的答案解决了我的问题 https://stackoverflow.com/a/26961576/2883980

毕竟,我现在有了一个解决方案,但不知道根本原因。

我会把它放在这里,这样其他人可能会觉得这很有用(因为我不知道 DYLD_LIBRARY_PATH 的用途)

man dyld

描述 动态链接器使用以下环境变量。
它们会影响任何使用动态链接器的程序。

  DYLD_FRAMEWORK_PATH
         This is a colon separated list of directories that contain 
         frameworks.  The  dynamic  linker searches  these  
         directories  before  it searches for the framework by its 
         install name.  It allows you to test new versions of 
         existing frameworks. (A framework is  a  library  install
         name  that  ends  in the form XXX.framework/Versions/YYY/XXX 
         or XXX.framework/XXX, where XXX and YYY are any name.)

         For each framework that a program uses, the dynamic linker 
         looks for the framework  in  each directory  in 
         DYLD_FRAMEWORK_PATH in turn. If it looks in all the 
         directories and can't find the framework, it searches the 
         directories in DYLD_LIBRARY_PATH in turn. If it  still  
         can't find   the   framework,   it   then  searches 
         DYLD_FALLBACK_FRAMEWORK_PATH  and  DYLD_FALL-
         BACK_LIBRARY_PATH in turn.

         Use the -L option to otool(1).  to discover the frameworks 
         and  shared  libraries  that  the executable is linked 
         against.

【问题讨论】:

    标签: python scrapy


    【解决方案1】:

    我注意到您安装了 scrapy 版本 0.24.4。您没有运行新版本 1.0 的任何原因?

    我相信 Scrapy.spiders 是 1.0 类,而不是 0.24 类。我会尝试在您的环境中安装真正的最新版本,看看是否可行。

    【讨论】:

    • conda 似乎默认安装此版本。根据您的建议查看我的编辑。
    • 我想我已经走到了尽头。似乎scrapy库的结构发生了很多变化。一些曾经有效的进口,现在不再有效。 from scrapy.spiders import Spider ==> 这是基于 Scrapy 1.0 结构的。如果你想使用 0.24 版本运行相同的导入,它应该如下所示: from scrapy.contrib.spiders import Spider
    【解决方案2】:

    我的工作与你完全相同。

    我按照这里的步骤创建了一个环境:

    Create the environment

    在这里激活我的环境:

    Activate the newly created environment

    我正在使用 anaconda 命令提示符解决这些问题。

    我很久以前安装了Scrapy,因此当我创建环境时,scrapy 已经在那里了。

    目前我在导入 items.py 时遇到问题: My question

    如果我能提供更多帮助,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 1970-01-01
      • 2019-02-12
      相关资源
      最近更新 更多