PYTHONPATH: dev and prod
jacopo
jacopo.pecci at gmail.com
Wed Jun 12 07:09:00 EDT 2013
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... at 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>
More information about the Python-list
mailing list