Created
April 19, 2022 04:49
-
-
Save TheProjectsGuy/a998c0a53313ee0bdc937018603d93a4 to your computer and use it in GitHub Desktop.
A gimmick to add a path to python interpreter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from pathlib import Path | |
# Set the "./../lib" from the script folder | |
dir_name = None | |
try: | |
dir_name = os.path.dirname(os.path.realpath(__file__)) | |
except NameError: | |
print("WARN: __file__ not found, trying local") | |
dir_name = os.path.abspath('') | |
lib_path = os.path.realpath(f"{Path(dir_name).parent}/lib") | |
# Add to path | |
if lib_path not in sys.path: | |
print(f"Adding library path: {lib_path} to PYTHONPATH") | |
sys.path.append(lib_path) | |
else: | |
print(f"Library path {lib_path} already in PYTHONPATH") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Allows you to add a library folder to
PYTHONPATH
. This is done if you want to use a library and are too lazy to create a python package out of that library.