Reputation: 189
I am trying to run a second file. I copied everything from a video and I still get this error.
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
I also tried setting the path to the absolute path and put it inside a raw string:
r'C:\Users\User\PycharmProjects\MyProject\file.py'
````but I get the same error
Upvotes: 0
Views: 189
Reputation: 66
First, you can change python3 to python or py because it isn't default in Windows. python3 works in linux.
You can try to use pathlib library to get the correct path.
from pathlib import Path
current_path = Path.cwd()
current_path shows the path of your file, then you change self.path to this:
self.path = current_path / path
Upvotes: 1
Reputation: 643
[Info] 'Python3' isn't default for windows. Try to use : 'py' or 'python'
/!\ Please give us all of TracBack error /!\
Upvotes: 0