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

Wildman best_lay at yahoo.com
Fri Feb 3 14:07:33 EST 2017


On Fri, 03 Feb 2017 12:58:15 -0600, Wildman wrote:

> On Fri, 03 Feb 2017 11:06:00 -0500, Neal Becker wrote:
> 
>> I want to make sure any modules I build in the current directory overide any 
>> others.  To do this, I'd like sys.path to always have './' at the beginning.
>> 
>> What's the best way to ensure this is always true whenever I run python3?
> 
> In python, this method will work but it is only in effect
> for the running process that calls it while it is running.
> It is not system wide and it is not permanent.
> 
> import os
> os.environ["PATH"] = os.environ["PATH"] + ":./"
>   or
> os.environ["PATH"] = "./:" + os.environ["PATH"]
> 
> (assuming Linux platform)
> To make it permanent for a certain user, add one of
> these lines to /home/user/.profile and log out/in:
> 
> PATH="$PATH:./"
>   or
> PATH="./:$PATH"
> 
> To make it permanent for all users, add one of
> these pairs of lines to /etc/rc.local and reboot:
> 
> export PATH=$PATH:./
> exit 0
>   or
> export PATH=./:$PATH
> exit 0
> 
> Add 'exit 0' only if it doesn't exist already and it
> must be the last line.  If /etc/rc.local does not
> exist, create it.

Sorry, I forgot something important.  If you use
/etc/rc.local, the execute bit must be set.

-- 
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!



More information about the Python-list mailing list