0
def hmsbookings() :
    os.system('python hmsbookings.py')
    root.after(60000, hmsbookings)

I tried these both lines, but for some reasons, it's not working out. It shows error :

/System/.../MacOS/Python: can't open file 'hmsbookings.py': [Errno 2] No such file or directory.

4
  • Where does the hmsbookings.py file located? Is it under the mentioned path /System/.../MacOS/Python? Commented Dec 8, 2021 at 10:23
  • no, it's located in my workspace folder. Not in Python folder. Commented Dec 8, 2021 at 10:34
  • This is what the error message try to tell you. It searches in the python folder. Use absolute path when launching a new script. Commented Dec 8, 2021 at 10:38
  • how to do that? Commented Dec 8, 2021 at 10:47

1 Answer 1

0

The execution path could be different where the file is located.
In your case, the execution is in /System/.../MacOS/Python however your file is somewhere else. This misbehavior could be resolved if you use the full path of the file.

Let me assume, that your file is located in your Desktop. Then this is the modified code that uses absolute path.

import os
def hmsbookings() :
    os.system('python os.path.expanduser("~/Desktop/hmsbookings.py")')
    root.after(60000, hmsbookings)

I'm not familiar with macOS, I based on this question. If you need more information about absolute path on mac see this question.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks! Btw, I tried this method def hmsbookings() : my_dir = os.path.dirname(sys.argv[0]) os.system('%s %s %s' % (sys.executable, os.path.join(my_dir, 'hmsbookings.py'), os.path.join(my_dir, 'Argument'))) It worked out for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.