I have the following folder structure
- lib
- my_module
I have moved all the libraries I need into the lib/ folder.
In my module/__init__.py, I think I will do:
import sys
sys.path.append('../lib/')
import my_dependency
Then when I need to use this dependency, I will refer to it as
my_module.my_dependency
Is this a bad usage of Python import?
NOTE: the dependencies consists of some third-party libraries not available via pip/easy_install and some C++ stuff that I wrote.
sys.path.append('../lib/')assumes that the current working directory is the directory of your script, which may or may not be the case.A version that doesn’t depend on the working directory is:
The above in plain language takes the full path to the script, chops off the last two components (script directory and script filename) and appends
lib.