0

I am having trouble using os.execv() in Python.

I have a file called test-exec.py that should call another file called helloworld.py (this file should just print hello world). I want the test-exec.py to run helloworld.py

test-exec.py looks like the below:

import sys
import os
if __name__ == '__main__':
   os.execv("usr/bin/python3", ['helloworld.py'])

when running the terminal with the command python3 test-exec.py helloworld.py (the helloworld.py is unnecessary right now) I get this error:

FileNotFoundError:[Errno 2] No such file or directory

but the file helloworld.py is in the directory: here

I'm using a virtual machine if that helps any.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • Does this answer your question? [How can I make one python file run another?](https://stackoverflow.com/questions/7974849/how-can-i-make-one-python-file-run-another) – Tomerikoo Jan 31 '21 at 18:20
  • Shouldn't it be `/usr/bin/python3`? (missing one slash in the start...) – Tomerikoo Jan 31 '21 at 18:24

1 Answers1

0

You can just go with the os.system() command. Try using something like this:

If they are in the same directory:

os.system("python3 helloworld.py")

Or if they are not in the same directory:

os.system("python3 path/to/the/file.py")