changing sys.path

Rick Johnson rantingrickjohnson at gmail.com
Wed Feb 1 12:17:04 EST 2012


On Feb 1, 10:15 am, Andrea Crotti <andrea.crott... at gmail.com> wrote:
> So suppose I want to modify the sys.path on the fly before running some code
> which imports from one of the modules added.
>
> at run time I do
> sys.path.extend(paths_to_add)
>
> but it still doesn't work and I get an import error.
>
> If I take these paths and add them to site-packages/my_paths.pth
> everything works, but at run-time the paths which I actually see before
> importing are exactly the same.

1. Is paths_to_add a nested list?
2. Have you tried inspecting the contents of sys.path AFTER calling
extend method?

Consider:
py> sys.path.__len__()
14
py> sys.path.extend([[1,2,3]])
py> sys.path.__len__()
15



More information about the Python-list mailing list