best way to ensure './' is at beginning of sys.path?

Steve D'Aprano steve+python at pearwood.info
Fri Feb 3 21:59:04 EST 2017


On Sat, 4 Feb 2017 01:13 pm, Cameron Simpson wrote:

>>1. In your .bashrc file, or equivalent, set the environment
>>   variable PYTHONPATH:
>>export PYTHONPATH='./;$PYTHONPATH'
> 
> You want double quotes (allowing parameter substitution) instead of single
> quotes here. Or, of course, no quotes at all. And the separator is ":",
> not ";".

Thanks for the correction.

> Personally, I'm against hacking the $PYTHONPATH this way at all.

Oh? Why's that? This is the whole purpose of PYTHONPATH.


> Far better to invoke the Python script via a shell script that includes
> the absolute path of the current directory (or the module directory) in
> the $PYTHONPATH.

For some definition of "better" -- that means you have double the cognitive
load. For every script.py you want, you need to create both script.py (what
you actually want) and script.sh (a wrapper that sets the environment).




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list