I have a Python script in a file stored in a Folder MyFolder. Tree structure for the file system is the following
MyFolder
- Image
- scipt_image.py
- script.py
- script_test.py
I want to use scripts in Image, scipt_image.py, in script script.py. To include this script_image.py, I use this :
import os, sys
DATA_DIR = os.path.abspath(os.path.join(os.getcwd(), 'Image'))
sys.path.append(DATA_DIR)
Then, i import script_image.py, with
import scipt_image
From errors at compilation, this seems not be working. However, problem may come from something else. Does this sounds correct ?
thanks
Is there a specific reason you don’t simply use the
Imagefolder as a python package and import the file directly without messing with sys.path?I would simply turn
Imageinto a python package (create an empty file named__init__.pyinImage) and then importscript_imagelike this: