1

I tried several ways but never succeeded. I need to change the directory in digital ocean (/home/vagrant). I have files saved in the same folder as where the file.py file is. file.py and other files that file.py aims to execute are all in /folder/PH/Programs. When I ran $python file.py, it appeared an error of the directory:

os.chdir('/folder/PH/Programs')


OSError: [Errno 2] No such file or directory:   '/folder/PH/Programs'
yearntolearn
  • 1,064
  • 2
  • 17
  • 36
  • 1
    The directory you've asked for (`/folder/PH/Programs`) doesn't exist. In which folder is `file.py`? – AlG Jul 08 '16 at 17:48
  • Thank you for the quick response. I edited my question. file.py is in `folder/PH/Programs`. Should I have something like 'i: ~/folder/PH/Programs'? – yearntolearn Jul 08 '16 at 17:50
  • @Hsun-YiHsieh Yeah, it should start from the home directory. Try with `~/folder`. It worked, right? – harshit-sh Jul 08 '16 at 18:01
  • @Hsun-YiHsieh I think you are confusing yourself. The directory with the slash before "folder" does not exist, and is in fact the cause of your error. How can it work now? –  Jul 08 '16 at 18:04
  • Yes, @super_cr7, ~/folder works, and the full path suggested by J.C. Rocamonde works, too. Thank you all! – yearntolearn Jul 08 '16 at 18:07

1 Answers1

1

Either you provide the full path to file, or do not put a slash at the beginning. That means the root directory.

go with:

os.chdir('~/folder/PH/Programs')

If it is in your home directory, or otherwise specify the full path to file.

(In fact, the path you say in your question is wrong for the same reason).