First, the folder you’re adding to sys.path should be L:\Pers_Personal\Pers_Scripts\Scripts_Me
. If you think about it, you’re going to want to have multiple modules in your Scripts_Me
folder. Maybe ThisProject
ThatProject
and AnotherProject
. So you want to add the folder where all your projects are going to live instead of adding each project individually. That way you can access any of them.
With only that change, the import will be from ThisProject.FaceRetarget import FaceRetarget
Also, you don’t need to do the saved_path = sys.path
thing. In that case, you’re just aliasing sys.path
, and it’s just an extra step that does absolutely nothing behind the scenes, and adds confusion. Just check if current_folder not in sys.path
Also, I see your folder path is using backslashes, but you’re not using a rawstring. You should definitely be doing that. Note the “r” in front of the quote: current_folder = r"L:\Pers_Personal\Pers_Scripts\Scripts_Me"
If you’re dealing with reload
, then my personal preference is to only deal with the top level module. Meaning, just import ThisProject
. Then your reload is reload(ThisProject)
. And after that line, you can do FaceRetarget = ThisProject.FaceRetarget.FaceRetarget
. This ensures that FaceRetarget
is always from the currently imported version of ThisProject
, and any calls to objects defined outside of your FaceRetarget.py
file, but still in ThisProject
will ALSO get reloaded at the same time.
IMO, It’s a good pattern to save you a bunch of hassle down the road.
Finally, you should be using newstyle classes by inheriting from object: class FaceRetarget(object):
I’m sure it won’t actually change anything for you in this project. But it’s a good habit to get into. Otherwise, when it actually does matter it’s just a pain to go back and fix.
import sys
import os
current_folder = r"L:\Pers_Personal\Pers_Scripts\Scripts_Me"
if current_folder not in sys.path:
sys.path.append(current_folder)
import ThisProject
reload(ThisProject)
FaceRetarget = ThisProject.FaceRetarget.FaceRetarget
FaceRetarget().run_the_script()