Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19729

Re: changing sys.path

Date 2012-02-01 17:47 +0000
From Andrea Crotti <andrea.crotti.0@gmail.com>
Subject Re: changing sys.path
References <4F296509.60607@gmail.com> <CALFfu7D16_uCoFNVcU6CjErLYYaOQJosfH41Gsm=N47bWpJs5Q@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5313.1328118446.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 02/01/2012 05:13 PM, Eric Snow wrote:
> On Wed, Feb 1, 2012 at 9:15 AM, Andrea Crotti<andrea.crotti.0@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.
> Make sure you are adding to sys.path the directories that your
> packages/modules are in, and not the actual package directories.
> During import Python looks for modules/packages _in_ each of the
> directories on sys.path, but not _at_ those directories.

Yes sure I do this..
>
>> 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.
> You mean sys.path looks exactly the same in the two cases?
>
> -eric

Yes they are exactly the same, because in that file I just write exactly 
the same list,
but when modifying it at run-time it doesn't work, while if at the 
application start
there is this file everything works correctly...

That's what really puzzles me.. What could that be then?

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: changing sys.path Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-02-01 17:47 +0000
  Re: changing sys.path Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-02 00:51 +0000
    Re: changing sys.path Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-02-02 10:03 +0000
      Re: changing sys.path jmfauth <wxjmfauth@gmail.com> - 2012-02-02 05:45 -0800

csiph-web