Setting PYTHONPATH from Makefile

Inyeol Lee inyeol.lee at siliconimage.com
Fri Dec 2 19:54:29 EST 2005


On Fri, Dec 02, 2005 at 07:33:20PM -0500, Mike Meyer wrote:
> "pinkfloydhomer at gmail.com" <pinkfloydhomer at gmail.com> writes:
> > I have a Makefile target that uses a python script, like:
> >
> > %.abc: %.def
> >         python myscript.py
> >
> > The problem is that myscript.py and some modules that myscript.py
> > imports are not in the current directory, but in another place in the
> > filesystem, say, /path/to/stuff. If this was a tcsh script, I would
> > just do:
> >
> >        setenv PYTHONPATH /path/to/stuff
> >        python myscript.py
> 
> And that still wouldn't work, because you said that myscript.py wasn't
> in the current directory either.
> 
> > but this cannot be done from a Makefile. So what do I do? Is there
> > another way to set the PYTHONPATH? Like giving an option to "python"
> > itself? Or?
> 
> No, you can't. You have to tweak the makefile. Try:
> 
> %.abc: %.def
>        (cd /path/to/myscripts/dir; python myscript.py)
> 
> 
> N.B. - this probably depends on both the system and the make you're
> using.
> 

How about using python -m?
Assuming Make uses Bourne shell,

%.abc: %.def
    PYTHONPATH=/path/to/stuff:/path/to/another python -m myscript


Don't forget to strip '.py' extension.

--Inyeol Lee



More information about the Python-list mailing list