0

I have a workspace called "bi-etl". The structure is as follows:

├───bi-etl
│   ├───utils
│   │   ├───file_a.py
│   │   └───file_b.py
│   ├───googlesheet
│   │   ├───parameter_update.py

The parameter_update.py is intended to import file_a.py and file_b.py from the utils folder, which as you can see, is not in the same folder as parameter_update.py which is in the googlesheet folder.

Following the link: Importing files from different folder

I tried the following but none seems to work so far.

Method 1: (Content of parameter_update.py)

#import modules
import pandas as pd
import json
import requests
import urllib.parse as urlparse
from datetime import datetime
import os
import sys
import importlib.util

sys.path.insert(0, '/C:/bi-etl/utils/file_a.py')
sys.path.insert(0, '/C:/bi-etl/utils/file_b.py')
from file_a import logger, report
from file_b import get_env, get_path

returns ModuleNotFoundError: No module named 'file_a'

Trying another method,

based on "from application.app.folder.file import func_name"

(content of parameter_update.py)

#import modules
import pandas as pd
import json
import requests
import urllib.parse as urlparse
from datetime import datetime
import os
import sys
import importlib.util

from bi-etl.utils.file_a import logger

returns

from bi-etl.utils.file_a import logger
        ^
    SyntaxError: invalid syntax
luc
  • 83
  • 6

1 Answers1

0

Perhaps not the most graceful solution but I have found one using the sys library.

I added the module to the path, then used import statement for the module name.

An example:

import sys
sys.path.append('**whole path to module**') # /C:/bi-etl/utils/ for example
import file_a
Berk Buzcu
  • 41
  • 3