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 9889
[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.or g> 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********@sil iconimage.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.or g> 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********@sil iconimage.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 machine from Python 1.5.2 to 2.2.3
(in a separate directory). Using the Pythowin Pythonpath browser, I
edited the python path to add my scripts directories. Then I tried to
import my scripts and they're not visible. I tried many things:
-...
|
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 think that the pythonpath-variable must be expanded to the location
|
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 PYTHONPATH unnecessary? Or am I missing something?
|
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 PyImport_Import("xyz"), Python returns an error "No
module named xyz". The problem _seems_ to be that I had no PYTHONPATH
variable defined (though python-shell works ok regardless), since the
following in bash helps:
|
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
Variables and created a System Variable called PYTHONPATH with the
value:
G:\Python22\lib\site-packages\Pythonwin;
| |
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 what
gets loaded where and when. However I can't find the documentation on
this.
Googling for 'python PYTHONPATH' give me a bunch of stuff about
setting the pythonpath for a specific app or about pythonpath itself but
|
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 make my path persistant?
Thanks
|
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 capture of what I did. Note that my newfolder appears
nowhere on the list of directories in sys.path. How do I get Python
to pay attention to my shell variables?
Using bash on OS X 10.4.10.
|
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" reports no errors
if i export PYTHONPATH:
export PYTHONPATH=/var/www/projects/uv_portal/portal
python -c "import MySQLdb" reports no errors as in previous case
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |