python 子进程:FileNotFoundError
python subprocess: FileNotFoundError
我正在尝试 运行 第二个文件。我从视频中复制了所有内容,但仍然出现此错误。
from subprocess import call
class CallCourses(object):
def __init__(self, path=r'file2.py'):
self.path = path
def call_module(self):
call(["Python3", f"{self.path}"])
if __name__ == '__main__':
c = CallCourses()
c.call_module()
FileNotFoundError: [WinError 2] The system cannot find the file specified
我还尝试将路径设置为绝对路径并将其放入原始字符串中:
r'C:\Users\User\PycharmProjects\MyProject\file.py'
````but I get the same error
[信息] 'Python3' 不是 windows 的默认设置。尝试使用:'py' 或 'python'
/!\ 请给我们所有的 TracBack 错误 /!\
首先,你可以把python3改成python或者py 因为它在 Windows 中不是默认值。 python3 适用于 linux.
您可以尝试使用pathlib库获取正确的路径。
from pathlib import Path
current_path = Path.cwd()
current_path显示你文件的路径,然后你把self.path改成这样:
self.path = current_path / path
我正在尝试 运行 第二个文件。我从视频中复制了所有内容,但仍然出现此错误。
from subprocess import call
class CallCourses(object):
def __init__(self, path=r'file2.py'):
self.path = path
def call_module(self):
call(["Python3", f"{self.path}"])
if __name__ == '__main__':
c = CallCourses()
c.call_module()
FileNotFoundError: [WinError 2] The system cannot find the file specified
我还尝试将路径设置为绝对路径并将其放入原始字符串中:
r'C:\Users\User\PycharmProjects\MyProject\file.py'
````but I get the same error
[信息] 'Python3' 不是 windows 的默认设置。尝试使用:'py' 或 'python'
/!\ 请给我们所有的 TracBack 错误 /!\
首先,你可以把python3改成python或者py 因为它在 Windows 中不是默认值。 python3 适用于 linux.
您可以尝试使用pathlib库获取正确的路径。
from pathlib import Path
current_path = Path.cwd()
current_path显示你文件的路径,然后你把self.path改成这样:
self.path = current_path / path