best way to ensure './' is at beginning of sys.path?
Neal Becker
ndbecker2 at gmail.com
Sat Feb 4 08:10:46 EST 2017
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?
Sorry if I was unclear, let me try to describe the problem more precisely.
I have a library of modules I have written using boost::python. They are
all in a directory under my home directory called 'sigproc'.
In ~/.local/lib/python3.5/site-packages, I have
--- sigproc.pth
/home/nbecker
/home/nbecker/sigproc
---
The reason I have 2 here is so I could use either
import modA
or
import sigproc.modA
although I almost always just use
import modA
.
Now I have started experimenting with porting to pybind11 to replace
boost::python. I am working in a directory called pybind11-test.
I built modules there, with the same names as ones in sigproc.
What I observed, I believe, is that when I try in that directory,
import modA
it imported the old one in sigproc, not the new one in "./".
This behavior I found surprising. I examined sys.path, and found it did not
contain "./".
Then I prepended "./" to sys.path and found
import modA
appeared to correctly import the module in the current directory.
I think I want this behavior always, and was asking how to ensure it.
Thanks.
More information about the Python-list
mailing list