0

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) enter image description here

Joshua Varghese
  • 5,082
  • 1
  • 13
  • 34

1 Answers1

1

"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.

Peter
  • 10,959
  • 2
  • 30
  • 47