[英]How to resolve “ModuleNotFoundError” No module named 'XXXX'
Im working with scrapy, within Spyder/Anaconda environment. 在Spyder / Anaconda环境中,我工作忙碌。 I have a project im trying to use the items.py with and no matter what i do, i cant get it to recognize it, keep getting "ModuleNotFoundError"
我有一个项目,即时通讯试图与items.py一起使用,无论我做什么,我都无法识别它,不断收到“ ModuleNotFoundError”
Here is what i have in my dsg_spider.py and items.py file. 这是我的dsg_spider.py和items.py文件中的内容。 As long as i dont try to use the items.py file within the spider, it runs and works as expected.. Im just trying to get the data in a structured format and want to set it up right before i proceed.
只要我不尝试在Spider中使用items.py文件,它就会按预期运行并运行。.我只是想以结构化格式获取数据并希望在我继续之前进行设置。
import scrapy
import sys
import os
from DSG2.items import Dsg2Item
doc = Dsg2Item()
doc['sku'] = response.xpath("//span[@itemprop='sku']/text()").extract()
doc['price'] = response.xpath("//span[@itemprop='price']/text()").extract()
doc['description'] = response.xpath("//meta[@itemprop='name']/@content").extract()
File "F:/Anaconda/DSG2/DSG2/spiders/dsg_spider.py", line 4, in from DSG2.items import Dsg2Item 从DSG2.items导入文件“ F:/Anaconda/DSG2/DSG2/spiders/dsg_spider.py”第4行,导入Dsg2Item
ModuleNotFoundError: No module named 'DSG2' ModuleNotFoundError:没有名为“ DSG2”的模块
This is the code within the items.py 这是items.py中的代码
import scrapy
class Dsg2Item(scrapy.Item):
description = scrapy.Field()
sku = scrapy.Field()
price = scrapy.Field()
#brand = brand
#description = name
The folder structure where i have all my files 我拥有所有文件的文件夹结构
Anaconda (folder)
DSG2 (folder)
|---DSG2 (folder)
|---_pycache_ (folder)
|---spiders (folder)
|---_pycache_ (folder)
|---_init_.py (file)
|---dsg_spider.py (file)
|---_init_.py (file)
|---items.py (file)
|---middlewares.py (file)
|---pipelines.py (file)
|---settings.py (file)
|---scrapy.cfg (file)
在我看来,解决方案是在Spyder中,转到Projects --- New Project ---选择Existing目录,然后导航到project文件夹并选择create,创建了一个项目,当我运行它时,它不再抱怨..
I think your forgot to add your package to the pythonpath. 我认为您忘记了将软件包添加到pythonpath中。
import sys
sys.path.insert(0, "/path/to/your/package_or_module")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.