Help Center> ModelArts> FAQs> Training Jobs> Compiling the Training Code> How Do I Obtain the Path for Storing the Dependency File in Training Code?

How Do I Obtain the Path for Storing the Dependency File in Training Code?

The code developed locally needs to be uploaded to the ModelArts backend. In training code, it is error-prone to set the path for storing the dependency file.

The following general solution is recommended: Use the OS API to obtain the absolute path to dependency files.

Example:

|---project_root                # Root directory for code
   |---BootfileDirectory        # Directory where the boot file is located
     |---bootfile.py            # Boot file
   |---otherfileDirectory       # Directory of other dependency files
     |---otherfile.py           # Other dependency files
    

Do as follows to obtain the path of the dependency file, otherfile_path in this example, in the boot file:

import os
current_path = os.path.dirname(os.path.realpath(__file__)) # Directory where the boot file is located
project_root = os.path.dirname(current_path) # Root directory of the project, which is the code directory set on the ModelArts training console
otherfile_path = os.path.join(project_root, "otherfileDirectory", "otherfile.py")