Reputation: 5202
According to this Question , it is said that to use a library or file from local folder, we use:
import sys
sys.path.append("/path/to/your/directory")
But what my doubt is that, is :
import sys
sys.path.append("/path/to/your/directory")
and:
locals()['path'].append("/path/to/your/directory")
and:
globals()['path'].append("/path/to/your/directory")
do the same function to import the directory files, or do vary by de-merits?
(I haven't seen any discussion about this anywere else)
Upvotes: 0
Views: 98
Reputation: 12315
"Hacking" the sys.path to enable imports is bad practice. Use editable installs instead:
pip install --editable /path/to/your/directory
This will insert a symlink of your project into the site-packages folder and allow Python to properly find your packages.
Upvotes: 1