changing sys.path

Dave Angel d at davea.name
Fri Feb 10 09:24:50 EST 2012


On 02/10/2012 08:08 AM, Andrea Crotti wrote:
> I think I finally located the issue with the sys.path extension.
>
> The problem is that I have many namespace directories, for example
>
> lib:
>  - sub1
>  - sub2
>
> lib:
>   - sub3
>   - sub4
>
> But to have everything working I had lib.sub3 in easy-install.pth.
> Now if I try to add something else to the path it doesn't take care of 
> the namespace
> declaration
> (every __init__.py in the packages contains: 
> __import__('pkg_resources').declare_namespace(__name__))
> and just doesn't find the other submodules..
>
> If I try to add manually lib.sub1, lib.sub2 changing the sys.path the 
> imports will only work for the first one.
>
> Strangely if I just create a dev_main.pth in site-packages containing 
> the same paths, everything works perfectly.
>
> Any suggestions now that the problem is more clear?
> Thanks,
> Andrea

The only code I saw in this thread was:

sys.path.extend(paths_to_add)

Can you add a print of paths_to_add, and of sys.path after you execute it?

If there's only one path, are you putting it in a list anyway?  If not 
then it won't do what you expect.



-- 

DaveA




More information about the Python-list mailing list