I have a module located in a different directory. I want to import it in another module. When I try to import from the directory, I get a syntax error. How do I import other local modules?
from "C:\User\Sam\module" import abc
I have a module located in a different directory. I want to import it in another module. When I try to import from the directory, I get a syntax error. How do I import other local modules?
from "C:\User\Sam\module" import abc
Ideally, you should build and install packages the standard way. Using a virtualenv and pip will set up your path for you, and install/symlink modules in a standard location. If for some reason you don't want to do that, see below.
If the module is not in the working directory you started Python from, add the folder containing your module to the path, then import the module by name.
import sys
sys.path.insert(0'C:/User/Sam/local_modules')
import my_module
Modifying the path is never necessary if you follow the standard package guidelines.