Reputation: 25226
Is it possible to specify directories to search for python imports in the python startup command?
Environment variables are great but the loosely coupled dependency between a binary and required environment variables isn't ideal for my case (a 1-liner is better than a 2 liner for extra foolproofness; I know you can do the 1.5 liner where you put the shell variable assignment as a prefix to the command you're about to execute).
Upvotes: 2
Views: 214
Reputation: 330073
PYTHONPATH
environmental variable is used to set sys.path
. It is a simple list of strings so you can always use sys.path.append
inside your module:
import sys
sys.path.append('/some/very/useful/path')
Note:
It can be particularly useful when combined with os.path.abspath
import os
sys.path.append(os.path.join(
os.path.abspath(os.path.dirname(__file__)), 'another/useful/directory'
))
Upvotes: 3