New to using sys.path
to enable module import from another directory, so I'm sure this is a noob question but:
Is it possible to not have to use the full/explicit or absolute file path when using sys.path
to access a Python script in another directory, but instead, to only provide the directory path that's local to the module file structure?
Currently, I have the following directory structure:
MyModule/
NAME/
__init__.py
bin/
userinfo.py
__init__.py
docs/
setup.py
tests/
NAME_tests.py
__init__.py
Within the setup.py file, I have it import the userinfo.py
script, which just asks the users for some info during installation. In the setup.py
file, the lines that call the userinfo.py
script look like this:
import sys
sys.path.insert(0, '/Users/malvin/PythonDev/projects/MyModule/bin')
import userinfo
This works fine, because I know the entire file path where the userinfo.py
file is, but obviously this doesn't work for someone who's trying to install the module because (obviously) there's no way to anticipate the file path on the user's system.
My question: Is there a method wherein I can import the userinfo.py
file (which lives in the /bin
folder) without having the entire system file path (that goes all the way up to /Users
) ? In other words, I'd like to just have something like:
import sys
sys.path.insert(0, 'MyModule/bin')
import userinfo
But I know this doesn't work.