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
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?
/David 5 9822
[pi************@gmail.com] I have a Makefile target that uses a python script, like:
%.abc: %.def python myscript.py
If this was a tcsh script, I would just do:
setenv PYTHONPATH /path/to/stuff python myscript.py
but this cannot be done from a Makefile.
Use:
%.abc: %.def
PYTHONPATH=/path/to/stuff python myscript.py
In fact, within Make or outside Make, for any shell command, you may
write:
VAR1=VALUE1 VAR2=VALUE2 ... COMMAND ARGUMENTS
so temporarily setting VAR1, VAR2... in the environment for the duration
of COMMAND only. This is a useful feature of the shell.
--
François Pinard http://pinard.progiciels-bpi.ca
"pi************@gmail.com" <pi************@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.
<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
On Fri, Dec 02, 2005 at 07:33:20PM -0500, Mike Meyer wrote: "pi************@gmail.com" <pi************@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
Inyeol Lee <in********@siliconimage.com> writes: On Fri, Dec 02, 2005 at 07:33:20PM -0500, Mike Meyer wrote: > 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
How about using python -m? Assuming Make uses Bourne shell,
%.abc: %.def PYTHONPATH=/path/to/stuff:/path/to/another python -m myscript
That will break __name__ (at least with 2.4.2). Whether or not it
matters will depend on the script.
<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
On Fri, Dec 02, 2005 at 08:10:41PM -0500, Mike Meyer wrote: Inyeol Lee <in********@siliconimage.com> writes: On Fri, Dec 02, 2005 at 07:33:20PM -0500, Mike Meyer wrote: > 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 How about using python -m? Assuming Make uses Bourne shell,
%.abc: %.def PYTHONPATH=/path/to/stuff:/path/to/another python -m myscript
That will break __name__ (at least with 2.4.2). Whether or not it matters will depend on the script.
$ python -V
Python 2.4.2
$ cat foo/bar.py
print __name__
$ (cd foo; python bar.py)
__main__
$ PYTHONPATH=$PWD/foo python -m bar
__main__
$
Am I missing something? I don't see any issue regarding __name__.
-- Inyeol Lee This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rami A. Kishek |
last post by:
Hi, I would really appreciate help on this from all ye Win-oriented
people. I have been using python under Linux for quite a while, know
little about windows.
I just upgraded my Python on WinME...
|
by: Eric Wichterich |
last post by:
Hello Pythonistas,
I am trying to get certain (self-written) libraries imported into my
scripts using statements like
"from library import function.py".
But they are not being found.
I...
|
by: r.e.s. |
last post by:
I have no PYTHONPATH nor any other python-related environment
variables, yet everything seems fine. (I'm using PythonWin
with winxp.) As long as modules are loaded through PythonWin,
is...
|
by: Tero Pihlajakoski |
last post by:
Hi,
I've been experimenting on embedding Python to a C software, and ran into
a little problem with PYTHONPATH (I'm running on linux). Here's the deal:
When trying to call...
|
by: D Denholm |
last post by:
I recently installed Python 2.2 on my WinXP box.
I am having problems figuring out how to create the PYTHONPATH
correctly.
I went to the WinXP SystemProperties > Advanced > Environment...
|
by: Neil Benn |
last post by:
Hello,
I'm trying to find some detailed documentation about
PYTHONPATH, paths.pth, lib/site-packages, sitecustomise and so on. I
know what they do but I'd like some detailed documentation about...
|
by: sushant.sirsikar |
last post by:
Hi,
I am using Linux env.I set the PYTHONPATH using
import sys
sys.path.append(----)
But we i close python and start again i is not showing my new entry in
PYTHONPATH.
Can anyone help me to...
|
by: mhearne808[insert-at-sign-here]gmail[insert-dot-he |
last post by:
I'm missing something major here. I'm trying to add a directory to my
python path using the PYTHONPATH environment variable, and it's being
ignored by the Python interactive shell.
Below is a...
|
by: Aljosa Mohorovic |
last post by:
i have a working MySQLdb module (/usr/lib/python2.4/site-packages/
MySQL_python-1.2.2-py2.4-linux-i686.egg), using it without problems.
"clean shell" after login:
python -c "import MySQLdb"...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |