Answer the question
In order to leave comments, you need to log in
How to import a Python module if it is not in the same script folder?
In the root folder there is a module and a folder with a script, tell me, please, is there a simple and elegant solution to import the module into the script?
root_folder/
subfolder/script.py
module.py
Answer the question
In order to leave comments, you need to log in
In subfolder you create an empty file with the expansion __init__.py (two underscores before and after init) and after that you can import it like this:
import subfolder.script
I solved the problem through environment variables, but as I understand it, the script will not run on another computer, maybe there is a more universal option
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question