changing sys.path
jmfauth
wxjmfauth at gmail.com
Wed Feb 1 12:06:40 EST 2012
On 1 fév, 17:15, 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.
>
> So there is something I guess that depends on the order, but what can I
> reset/reload to make these paths available (I thought I didn't need
> anything in theory)?
>>> import mod
Traceback (most recent call last):
File "<eta last command>", line 1, in <module>
ImportError: No module named mod
>>> sys.path.append(r'd:\\jm\\junk')
>>> import mod
>>> mod
<module 'mod' from 'd:\\jm\\junk\mod.py'>
>>> mod.hello()
fct hello in mod.py
sys.path? Probably, the most genious Python idea.
jmf
More information about the Python-list
mailing list