无法从.bat文件运行Scrapy Spider

wkyowqbh  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(217)

我试着从一个.bat文件中运行一个scrapy spider
当我运行.bat文件时,该文件包含以下文本:

@echo off
REM activate Python venv
CALL "D:\python\scrapy_projects\venv\Scripts\activate.bat"
CD "D:\python\scrapy_projects\digikalasellerdata\digikalasellerdata\spiders"
CALL "D:\python\scrapy_projects\venv\Scripts\python.exe" "D:\python\scrapy_projects\venv\Lib\site-packages\scrapy\cmdline.py" crawl my_deactivated -O kobs.csv
pause

我得到这个错误:

Traceback (most recent call last):
  File "D:\python\scrapy_projects\venv\Lib\site-packages\scrapy\cmdline.py", line 8, in <module>
    import scrapy
  File "D:\python\scrapy_projects\venv\lib\site-packages\scrapy\__init__.py", line 12, in <module>
    from scrapy.spiders import Spider
  File "D:\python\scrapy_projects\venv\lib\site-packages\scrapy\spiders\__init__.py", line 10, in <module>
    from scrapy.http import Request
  File "D:\python\scrapy_projects\venv\lib\site-packages\scrapy\http\__init__.py", line 8, in <module>
    from scrapy.http.headers import Headers
  File "D:\python\scrapy_projects\venv\lib\site-packages\scrapy\http\headers.py", line 3, in <module>
    from scrapy.utils.python import to_unicode
  File "D:\python\scrapy_projects\venv\lib\site-packages\scrapy\utils\python.py", line 16, in <module>
    from scrapy.utils.decorators import deprecated
  File "D:\python\scrapy_projects\venv\lib\site-packages\scrapy\utils\decorators.py", line 4, in <module>
    from twisted.internet import defer, threads
  File "D:\python\scrapy_projects\venv\lib\site-packages\twisted\internet\defer.py", line 44, in <module>
    from twisted.internet.interfaces import IDelayedCall, IReactorTime
  File "D:\python\scrapy_projects\venv\lib\site-packages\twisted\internet\interfaces.py", line 26, in <module>
    from twisted.python.failure import Failure
  File "D:\python\scrapy_projects\venv\lib\site-packages\twisted\python\failure.py", line 26, in <module>
    from twisted.python import reflect
  File "D:\python\scrapy_projects\venv\lib\site-packages\twisted\python\reflect.py", line 22, in <module>
    from twisted.python.compat import nativeString
  File "D:\python\scrapy_projects\venv\lib\site-packages\twisted\python\compat.py", line 35, in <module>
    from http import cookiejar as cookielib
  File "D:\python\scrapy_projects\venv\Lib\site-packages\scrapy\http\__init__.py", line 8, in <module>
    from scrapy.http.headers import Headers
ImportError: cannot import name 'Headers' from partially initialized module 'scrapy.http.headers' (most likely due to a circular import) (D:\python\scrapy_projects\venv\lib\site-packages\scrapy\http\headers.py)

有什么解决办法吗?
多谢了

yuvru6vn

yuvru6vn1#

不要直接调用Python文件,而是使用以下代码:

python -m scrapy crawl my_deactivated -O kobs.csv

这就是你激活虚拟环境的目的。

相关问题