我已经尝试在安装scrapy模块之后创建scrapy项目。最终出现以下错误。我已经在stackoverflow中搜索了一些解决方案。但是什么也找不到。
在目录test1中,创建了包含以下文件和文件夹的目录。那样我找不到settings.py。
test1
|-test1
|-__pycache__
|-spiders
|-__pycache__
|-__init__.py
|-__init__.py
|-scrapy.cfg
以下是在创建令人毛骨悚然的项目时返回的错误消息。
C:\Users\SIMBU\Personal\MyWork\PyPgm>scrapy startproject test1
Traceback (most recent call last):
File "d:\myFld\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\myFld\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\myFld\Python36\Scripts\scrapy.exe\__main__.py", line 9, in <module>
File "d:\myFld\python36\lib\site-packages\scrapy\cmdline.py", line 149, in execute
_run_print_help(parser, _run_command, cmd, args, opts)
File "d:\myFld\python36\lib\site-packages\scrapy\cmdline.py", line 89, in _run_print_help
func(*a, **kw)
File "d:\myFld\python36\lib\site-packages\scrapy\cmdline.py", line 156, in _run_command
cmd.run(args, opts)
File "d:\myFld\python36\lib\site-packages\scrapy\commands\startproject.py", line 109, in run
ProjectName=string_camelcase(project_name))
File "d:\myFld\python36\lib\site-packages\scrapy\utils\template.py", line 9, in render_templatefile
with open(path, 'rb') as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'test1\\test1\\settings.py.tmpl'
编辑: 临时安装后,项目创建将永远不会成功。文件夹(D:\ myFld \ Python36 \ Lib \ site-packages \ scrapy \ settings \ default_settings.py)中的目录文件如下
TEMPLATES_DIR = abspath(join(dirname(__file__), '..', 'templates'))
我的点显示如下结果。
C:\Users\SIMBU>pip show scrapy
Name: Scrapy
Version: 1.4.0
Summary: A high-level Web Crawling and Web Scraping framework
Home-page: http://scrapy.org
Author: Pablo Hoffman
Author-email: pablo@pablohoffman.com
License: BSD
Location: d:\myFld\python36\lib\site-packages
Requires: queuelib, lxml, w3lib, cssselect, Twisted, parsel, PyDispatcher, service-identity, pyOpenSSL, six
Required-by:
答案 0 :(得分:1)
当它应该查看繁琐的安装位置时,它正在尝试在正在创建的项目中查找模板文件。
在此之前的任何时候,您是否更改过TEMPLATES_DIR设置?您以前是否使用当前安装创建过项目?
(向社区致歉:我知道应该在评论中要求清楚,但是我没有足够的代表,我正在努力提供帮助)
答案 1 :(得分:0)
重新安装scrapy对我有用。这是我要解决的步骤。
C:\Users\SIMBU>pip uninstall scrapy
Uninstalling Scrapy-1.4.0:
Would remove:
d:\myFld\python36\lib\site-packages\scrapy-1.4.0.dist-info\*
d:\myFld\python36\lib\site-packages\scrapy\*
d:\myFld\python36\scripts\scrapy.exe
Proceed (y/n)? y
Successfully uninstalled Scrapy-1.4.0
C:\Users\SIMBU>
C:\Users\SIMBU>pip install scrapy
Collecting scrapy
Downloading https://files.pythonhosted.org/packages/5d/12/a6197eaf97385e96fd8ec56627749a6229a9b3178ad73866a0b1fb377379/Scrapy-1.5.1-py2.py3-none-any.whl (249kB)
100% |████████████████████████████████| 256kB 757kB/s
Requirement already satisfied: w3lib>=1.17.0 in d:\myFld\python36\lib\site-packages (from scrapy) (1.18.0)
Requirement already satisfied: service-identity in d:\myFld\python36\lib\site-packages (from scrapy) (17.0.0)
Requirement already satisfied: lxml in d:\myFld\python36\lib\site-packages (from scrapy) (4.1.1)
Requirement already satisfied: PyDispatcher>=2.0.5 in d:\myFld\python36\lib\site-packages (from scrapy) (2.0.5)
Requirement already satisfied: cssselect>=0.9 in d:\myFld\python36\lib\site-packages (from scrapy) (1.0.1)
Requirement already satisfied: Twisted>=13.1.0 in d:\myFld\python36\lib\site-packages (from scrapy) (17.9.0)
Requirement already satisfied: parsel>=1.1 in d:\myFld\python36\lib\site-packages (from scrapy) (1.2.0)
Requirement already satisfied: queuelib in d:\myFld\python36\lib\site-packages (from scrapy) (1.4.2)
Requirement already satisfied: pyOpenSSL in d:\myFld\python36\lib\site-packages (from scrapy) (18.0.0)
Requirement already satisfied: six>=1.5.2 in d:\myFld\python36\lib\site-packages (from scrapy) (1.11.0)
Requirement already satisfied: pyasn1-modules in d:\myFld\python36\lib\site-packages (from service-identity->scrapy) (0.2.1)
Requirement already satisfied: attrs in d:\myFld\python36\lib\site-packages (from service-identity->scrapy) (17.3.0)
Requirement already satisfied: pyasn1 in d:\myFld\python36\lib\site-packages (from service-identity->scrapy) (0.4.2)
Requirement already satisfied: constantly>=15.1 in d:\myFld\python36\lib\site-packages (from Twisted>=13.1.0->scrapy) (15.1.0)
Requirement already satisfied: zope.interface>=4.0.2 in d:\myFld\python36\lib\site-packages (from Twisted>=13.1.0->scrapy) (4.4.3)
Requirement already satisfied: hyperlink>=17.1.1 in d:\myFld\python36\lib\site-packages (from Twisted>=13.1.0->scrapy) (17.3.1)
Requirement already satisfied: incremental>=16.10.1 in d:\myFld\python36\lib\site-packages (from Twisted>=13.1.0->scrapy) (17.5.0)
Requirement already satisfied: Automat>=0.3.0 in d:\myFld\python36\lib\site-packages (from Twisted>=13.1.0->scrapy) (0.6.0)
Requirement already satisfied: cryptography>=2.2.1 in d:\myFld\python36\lib\site-packages (from pyOpenSSL->scrapy) (2.3.1)
Requirement already satisfied: setuptools in d:\myFld\python36\lib\site-packages (from zope.interface>=4.0.2->Twisted>=13.1.0->scrapy) (40.4.3)
Requirement already satisfied: cffi!=1.11.3,>=1.7 in d:\myFld\python36\lib\site-packages (from cryptography>=2.2.1->pyOpenSSL->scrapy) (1.11.2)
Requirement already satisfied: idna>=2.1 in d:\myFld\python36\lib\site-packages (from cryptography>=2.2.1->pyOpenSSL->scrapy) (2.6)
Requirement already satisfied: asn1crypto>=0.21.0 in d:\myFld\python36\lib\site-packages (from cryptography>=2.2.1->pyOpenSSL->scrapy) (0.23.0)
Requirement already satisfied: pycparser in d:\myFld\python36\lib\site-packages (from cffi!=1.11.3,>=1.7->cryptography>=2.2.1->pyOpenSSL->scrapy) (2.18)
Installing collected packages: scrapy
Successfully installed scrapy-1.5.1
C:\Users\SIMBU>
C:\Users\SIMBU>scrapy startprojct test
Scrapy 1.5.1 - no active project
Unknown command: startprojct
Use "scrapy" to see available commands
C:\Users\SIMBU>scrapy startproject test
Error: Module 'test' already exists
C:\Users\SIMBU>scrapy startproject test2
New Scrapy project 'test2', using template directory 'd:\\myFld\\python36\\lib\\site-packages\\scrapy\\templates\\project', created in:
C:\Users\SIMBU\test2
You can start your first spider with:
cd test2
scrapy genspider example example.com
C:\Users\SIMBU>