473,513 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search path for python script

grt
I'm new to python, running it under cygwin. This must be easy but I
haven't figured it out. I'm trying to run a script by typing:

python test.py

where test.py is in a directory I've added to PYTHONPATH, but test.py
is not found. Perhaps PYTHONPATH only applies to modules imported
within a script. I didn't notice an option to python to search the
standard path, like Perl -S.

How is this done?

Sep 12 '07 #1
5 1891
On Sep 12, 4:40 pm, grt <gary.thr...@navy.milwrote:
>
I'm trying to run a script by typing:

python test.py
What happens if you just type:

test.py or test

and hit Enter?

rd

Sep 12 '07 #2
grt
On Sep 12, 4:06 pm, BartlebyScrivener <bscrivene...@gmail.comwrote:
On Sep 12, 4:40 pm, grt <gary.thr...@navy.milwrote:
I'm trying to run a script by typing:
python test.py

What happens if you just type:

test.py or test

and hit Enter?

rd
test gives the error: command not found.
test.py gives the error: no such file.

Sep 13 '07 #3
grt wrote:
I'm new to python, running it under cygwin. This must be easy but I
haven't figured it out. I'm trying to run a script by typing:

python test.py

where test.py is in a directory I've added to PYTHONPATH, but test.py
is not found. Perhaps PYTHONPATH only applies to modules imported
within a script. I didn't notice an option to python to search the
standard path, like Perl -S.

How is this done?
The PYTHONPATH is only used to augment sys.path, which in turn is only
used for locating modules to import.

If you want to locate scripts then just put them on your PATH, and make
sure they are +x with a shebang line (#!/usr/bin/env python is the
commonest) at the head.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Sep 13 '07 #4
Am Wed, 12 Sep 2007 14:40:30 -0700 schrieb grt:
I'm new to python, running it under cygwin. This must be easy but I
haven't figured it out. I'm trying to run a script by typing:

python test.py

where test.py is in a directory I've added to PYTHONPATH, but test.py
is not found. Perhaps PYTHONPATH only applies to modules imported
within a script. I didn't notice an option to python to search the
standard path, like Perl -S.

How is this done?
python -m test

Peter
Sep 13 '07 #5
This works for me under cygwin.

Start the script with the line
#! /usr/bin/python

Place the script in a directory shown by the command
echo $PATH

Invoke the script using its name, i.e.

test.py
Sep 13 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9695
by: Stephen Ferg | last post by:
I need a little help here. I'm developing some introductory material on Python for non-programmers. The first draft includes this statement. Is this correct? ...
3
2350
by: Peter Schwalm | last post by:
I'd like to modify the python search path depending on the source directory of the script being started. The reason is: I use a version control system, and the python scripts and modules are...
8
1556
by: Darren Dale | last post by:
Is there a place to put python programs so I dont have to refer to the absolute path everytime I want to call them? For example: if I am in /home/me and want to execute: python...
1
8700
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
9
2823
by: PipedreamerGrey | last post by:
This is the beginning of a script that I wrote to open all the text files in a single directory, then process the data in the text files line by line into a single index file. ...
4
1458
by: boris | last post by:
I have two directories, lib1 and lib2, that both contain the package foo, one with the submodule mod1 and the other with the submodule mod2: $ ls lib*/foo/ lib1/foo/: __init__.py __init__.pyc...
1
1454
by: mhearne808[insert-at-sign-here]gmail[insert-dot-he | last post by:
I think I don't understand how the module search path works... Let's say I have a folders called 'test'. Underneath it, I create two more folders called 'foo' and 'bar'. In 'foo', I create an...
8
1546
by: tow | last post by:
I have a python script (part of a django application, if it makes any difference) which is exhibiting the following behaviour: import my_module # succeeds imp.find_module("my_module") # fails,...
2
1732
by: Mike Driscoll | last post by:
On Sep 25, 10:41 am, js <ebgs...@gmail.comwrote: Why not just add a custom path file (*.pth)? EasyInstall, wx, PyWin32 and others do it. Of course there's always sys.path.append as well. Mike
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7521
tracyyun
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...
0
5682
agi2029
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,...
1
5084
isladogs
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...
0
3232
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...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
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 ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.