I'm trying to make a relative import in python. but I can't understand the syntax and everytime I search for it here in SO, I can't get an answer:
Here is my folder structure:
Root
libraries
mylibrary
__init__
projects
project
myproject.py
and I want to import 'mylibrary' using a relative path, what's the syntax for doing it?
You have to add the directory to your python path.
import sys
sys.path.append("/libraries")
But I think it might be better to either put the libraries in the folders of the projects that need it or just install them to one of the standard places already in sys.path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With