gpt4 book ai didi

python - Windows 在目录中找不到 scrapy 文件

转载 作者:可可西里 更新时间:2023-11-01 10:47:28 26 4
gpt4 key购买 nike

所以我得到了一个简单的运行器脚本,它将使用 Popen 来调用蜘蛛程序。运行脚本如下:

from subprocess import Popen
import time
def runSpider():
p = Popen(["scrapy", "crawl", "spider1"],
cwd="C:\Users\Kasutaja\Desktop\scrapyTest")
stdout, stderr = p.communicate()
time.sleep(15)

runSpider()

目录是这样的:

 -----scrapyTest: 
--------------------scrapyTest[folder]: spider[folder], items.py, pipelines.py, settings.py
--------------------runner.py
--------------------scrapy.cfg

蜘蛛从目录完美运行:C:\Users\Kasutaja\Desktop\scrapyTest 当我从 cmd 行运行它时。

当我运行我的 runner.py 脚本时,我得到:

The system cannot find the file specified

编辑:

将 Popen 更改为:

p = Popen(["C:\Users\Kasutaja\Desktop\scrapyTest","scrapy", "crawl", "spider1"])

我得到错误:

    C:\Users\Kasutaja\Desktop\scrapyTest>python runner.py
Traceback (most recent call last):
File "runner.py", line 13, in <module>
runSpider()
File "runner.py", line 8, in runSpider
p = Popen(["C:\Users\Kasutaja\Desktop\scrapyTest","scrapy", "crawl", "spider
1"])
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 896, in _execute_child
startupinfo)
WindowsError: [Error 5] Access is denied

如果重要的话,我有管理员权限。我现在也尝试过,使用从开始菜单专门打开的 cmd 和管理员权限运行脚本,但仍然出现相同的错误。

最佳答案

来自文档

If cwd is not None, the child’s current directory will be changed to cwd before it is executed. Note that this directory is not considered when searching the executable, so you can’t specify the program’s path relative to cwd. (Emphasis mine)

对我来说这意味着你必须做类似的事情

Popen(["C:\Users\Kasutaja\Desktop\scrapyTest\scrapy", "crawl", "spider1"])

这将执行一个带有参数 crawlspider1 的程序 scrapy

关于python - Windows 在目录中找不到 scrapy 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17342098/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com