gpt4 book ai didi

python check_output 文件未找到错误 : [WinError 2] The system cannot find the file specified

转载 作者:太空宇宙 更新时间:2023-11-03 20:27:54 26 4
gpt4 key购买 nike

我正在运行下一段代码来检查文件的类型:

import subprocess as sub
output = sub.check_output(["file", "test.py"]).decode('ascii')
#output=sub.check_output(["file","C:/Users/Roger.That/PycharmProjects/test/test.py"]).decode('ascii')

我不断收到以下错误:

Traceback (most recent call last):

File "C:/Users/Roger That/PycharmProjects/test/test.py", line 2, in <module>
output = sub.check_output(["file", "test.py"]).decode('ascii')
File "C:\Users\Roger That\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 395, in check_output
**kwargs).stdout
File "C:\Users\Roger That\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 472, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\Roger That\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\Roger That\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

我的 test.py 的完整路径:"C:/Users/Roger.That/PycharmProjects/test/test.py"

gitbash 的输出:

$ file /c/Users/Roger\ That/PycharmProjects/test/test.py
/c/Users/Roger That/PycharmProjects/test/test.py: ASCII text, with CRLF line terminators

有没有可能与我在“Roger”和“That”之间有一个点有关?虽然当我使用相对路径(仅文件名)时它也不起作用

更新

我将用户的目录名称从 Roger that 更改为 Roger.that,但仍然没有帮助:

python /c/Users/Roger.That/PycharmProjects/test/test.py
same error..

还检查了:

import subprocess as sub
output = sub.check_output(["ls" "-l"])

遇到同样的错误

最佳答案

我从头开始创建了虚拟环境,它解决了我的问题。

关于python check_output 文件未找到错误 : [WinError 2] The system cannot find the file specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57699040/

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