Scrapy开始项目以ImportError结束:没有名为spiders的模块

时间:2015-07-15 01:50:48

标签: python scrapy

我用

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

我用

激活这个环境
source activate scraping

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

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的文件,如果我为class Spider grep,我在任何地方都没有这样的课程。

我首先在conda安装上做错了吗?我安装python 2.7,这是要求。

which openssl返回(我觉得很好)     /用户/亚历/ anaconda3 / ENVS /刮削/ bin中/ OpenSSL的

我们可以从conda list

看到

lxml已安装

我在这里有点无能为力。

[编辑] 正如评论中所提到的,我没有使用最新版本的废料。这并没有解释错误,但我继续用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.

1 个答案:

答案 0 :(得分:-1)

我正在完成与你完全相同的任务。

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

Create the environment

在这里激活我的环境:

Activate the newly created environment

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

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

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

如果我能进一步帮助,请告诉我。