How to import file from parent directory in python?
My project tree is as follows:
From __main__.py
file which is in vehiclesListCrawler
I want to import common.py
which is in a parent directory.
Now I do it as follows:
from common import get_init_url, create_urls_to_fetch, MILEAGE_RANGES, notify_on_error
But I'm getting an error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "./__main__.py", line 11, in <module>
from common import get_init_url, create_urls_to_fetch, MILEAGE_RANGES, notify_on_error
ModuleNotFoundError: No module named 'common'
Any idea?
UPDATE
Nothing from here didn't help. That is why I've posted the new question.
Inside __main__.py
I have main function as follows:
def main(params):
try:
process.crawl(AutoscoutListSpider, params)
process.start()
return {"Success ": main_result}
except Exception as e:
return {"Error ": e, "params ": params}
And I run it as follows:
main({"make":"Audi", "model":"A3", "mileage":"2500"})