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


Groups > comp.lang.python > #47780

Re: PYTHONPATH: dev and prod

Newsgroups comp.lang.python
Date 2013-06-12 04:09 -0700
References <e76ed600-524e-4e07-81c3-e6592bbd0b11@googlegroups.com> <2eed235a-5ac2-49d2-933b-1b6d324866ae@n5g2000pbg.googlegroups.com>
Message-ID <6e5f4c64-59aa-48c3-8759-97af4ff42e1b@googlegroups.com> (permalink)
Subject Re: PYTHONPATH: dev and prod
From jacopo <jacopo.pecci@gmail.com>

Show all headers | View raw


this idea seemed perfect but it turned out that you have to execute the module as a package (python -m scripts.myscript) otherwise I get an error on the relative import. 
Unfortunately I am working in a team and I do not have control on how the module is launched.


On Tuesday, June 11, 2013 6:14:43 PM UTC+1, rusi wrote:
> On Jun 11, 9:28 pm, jacopo <jacopo.pe...@gmail.com> wrote:
> 
> > I am developing my code in the path:
> 
> > /py/myscripts
> 
> > /py/mylib
> 
> > In order to "import mylib", I need to add /py/mylib to PYTHONPATH.
> 
> >
> 
> > Now I want to save a snapshot of the current code in the production directory, I will copy all in:
> 
> > /prod/myscripts
> 
> > /prod/mylib
> 
> >
> 
> > The problem now is that when I execute /prod/myscripts/any_script.py, every "import" will look at PYTHONPATH and therefore it will load the modules from /py/mylib. On the contrary I want to load it from /prod/mylib.
> 
> >
> 
> > Is there an elegant way to cope with this?
> 
> >
> 
> > thanks, Jacopo
> 
> 
> 
> <I-think>
> 
> Use explicit (dot-based) relative imports
> 
> http://docs.python.org/release/2.5/whatsnew/pep-328.html
> 
> Avoid using PYTHONPATH
> 
> </I-think>

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


Thread

PYTHONPATH: dev and prod jacopo <jacopo.pecci@gmail.com> - 2013-06-11 09:28 -0700
  Re: PYTHONPATH: dev and prod rusi <rustompmody@gmail.com> - 2013-06-11 10:14 -0700
    Re: PYTHONPATH: dev and prod jacopo <jacopo.pecci@gmail.com> - 2013-06-12 04:09 -0700
    Re: PYTHONPATH: dev and prod jacopo <jacopo.pecci@gmail.com> - 2013-06-12 04:10 -0700
      Re: PYTHONPATH: dev and prod rusi <rustompmody@gmail.com> - 2013-06-12 04:50 -0700
        Re: PYTHONPATH: dev and prod jacopo <jacopo.pecci@gmail.com> - 2013-06-12 06:29 -0700
          Re: PYTHONPATH: dev and prod rusi <rustompmody@gmail.com> - 2013-06-12 09:10 -0700
            Re: PYTHONPATH: dev and prod jacopo <jacopo.pecci@gmail.com> - 2013-06-13 03:52 -0700

csiph-web