【发布时间】: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.
【问题讨论】: