【python】TypeError: expected str, bytes or os.PathLike object, not NoneType

python版本:3.7

scrapy版本:1.7.1

 

问题描述

在这个目录下正常生成

(venv) G:\Users\Administrator\PycharmProjects\pythonPratice\code\spider\day04>scrapy genspider tttt itcast.cn
Created spider 'tttt' using template 'basic'
 

在下一级及以下目录生成失败,mySpider及以下为通过scrapy startproject生成

(venv) G:\Users\Administrator\PycharmProjects\pythonPratice\code\spider\day04\mySpider>scrapy genspider tttt itcast.cn

(venv) G:\Users\Administrator\PycharmProjects\pythonPratice\code\spider\day04\mySpider>scrapy genspider tttt itcast.cn
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "G:\Users\Administrator\PycharmProjects\pythonPratice\venv\Scripts\scrapy.exe\__main__.py", line 9, in 
  File "g:\users\administrator\pycharmprojects\pythonpratice\venv\lib\site-packages\scrapy\cmdline.py", line 146, in execute
    _run_print_help(parser, _run_command, cmd, args, opts)
  File "g:\users\administrator\pycharmprojects\pythonpratice\venv\lib\site-packages\scrapy\cmdline.py", line 100, in _run_print_help
    func(*a, **kw)
  File "g:\users\administrator\pycharmprojects\pythonpratice\venv\lib\site-packages\scrapy\cmdline.py", line 154, in _run_command
    cmd.run(args, opts)
  File "g:\users\administrator\pycharmprojects\pythonpratice\venv\lib\site-packages\scrapy\commands\genspider.py", line 82, in run
    self._genspider(module, name, domain, opts.template, template_file)
  File "g:\users\administrator\pycharmprojects\pythonpratice\venv\lib\site-packages\scrapy\commands\genspider.py", line 99, in _genspi
der
    spiders_dir = abspath(dirname(spiders_module.__file__))
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 221, in dirname
    return split(p)[0]
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 183, in split
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

错误信息

TypeError: expected str, bytes or os.PathLike object, not NoneType

 

解决:

将工程全部删除然后重建

#创建工程

scrapy startproject itcast

#进入下一级目录

cd itcast

#创建爬虫

scrapy genspider myspider itcast.com

 

总结

感觉很气,费了将近2个小时最后也不晓得具体的问题原因是什么,但是删了重建又是对的

你可能感兴趣的:(python)