我的项目结构:
kmss/
├── kmss
│ ├── __init__.py
│ ├── items.py
│ ├── pipelines.py
│ ├── settings.py
│ └── spiders
│ ├── __init__.py
│ └── first.py
├── README.rst
├── scrapy.cfg
└── setup.py
我在mac上运行它,我的项目文件夹是在/user/username/kmss
在items.py
内我有一个名为" KmssItem "
的班级。
如果我要运行first.py
(我的蜘蛛),我必须导入更高级别的items.py.
。
我遇到以下问题:
from kmss.items import KmssItem
在items.py
内,代码为:
from scrapy import Item, Field
class KmssItem(Item):
# define the fields for your item here like:
##image_urls= Field()
##Images = Field()
title = Field()
##url= Field()
pass
first.py
的代码
from scrapy.contrib.spiders import CrawlSpider , Rule
from scrapy.contrib.linkextractors import LinkExtractor
from kmss.items import KmssItem
class FirstSpider(CrawlSpider):
name = "first"
## you do not find it to go to facebook links
allowed_domains = ["www.reddit.com"]
start_urls = [
'http://www.reddit.com/r/pics/',
## some other codes
我正在使用anaconda spyder,我已将路径/users/username/kmss/kmss
添加到路径管理器。
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/username/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "/Users/username/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 78, in execfile
builtins.execfile(filename, *where)
File "/Users/username/kmss/kmss/spiders/first.py", line 4, in <module>
from kmss.items import KmssItem
ImportError: No module named kmss.items
有人可以帮忙解决这个问题吗?
提前谢谢
[更新]:
当我在spyder上运行first.py时,它显示了同样的错误 但是,如果我在anaconda命令提示符下运行,则不会发生错误。