Using PythonPath under Windows Vista.

  • Thread starter Morgul Banner Bearer
  • Start date
M

Morgul Banner Bearer

Hi Everybody,

I was using the O'Reilly book from 1999 to look into Python and ran
into a problem with
the use of Pythonpath.

I have Python installed under c:\python26.
I have the module "Brian.py" that i want to run installed under c
\python26\work

In Windows Vista, I have set an environment variable "Pythonpath"
equal to c:\python26\work
(by using the "My computer", "Properties", "Advanced", "Environment
Variables".

The behaviour of the program is as follows :
In a Dos Box, the program executes nicely when i type :
"c\python26>python c:\python26\work\brian.py".

Now i understand that- because I set the Pythonpath- the program
should also run if i type:
"c\python26>python brian.py"
(under these conditions Python should look for the file brian.py in
the folders specified in the
Pythonpath). However, this does not work, but gives : "Can't open
file... No such file or directory".

I have not found further info availlable on bulletin boards on the
internet, so if anybody can post
the solution here, that would help me out.

Thanks,
wim76.
 
A

Andrew Lewis

In Windows Vista, I have set an environment variable "Pythonpath"
equal to c:\python26\work
(by using the "My computer", "Properties", "Advanced", "Environment
Variables".
I always thought pythonpath was only for imports, try adding the
location to the regular path variable.

Andrew
 
S

Steve Holden

Morgul said:
Hi Everybody,

I was using the O'Reilly book from 1999 to look into Python and ran
into a problem with
the use of Pythonpath.

I have Python installed under c:\python26.
I have the module "Brian.py" that i want to run installed under c
\python26\work

In Windows Vista, I have set an environment variable "Pythonpath"
equal to c:\python26\work
(by using the "My computer", "Properties", "Advanced", "Environment
Variables".

The behaviour of the program is as follows :
In a Dos Box, the program executes nicely when i type :
"c\python26>python c:\python26\work\brian.py".

Now i understand that- because I set the Pythonpath- the program
should also run if i type:
"c\python26>python brian.py"
(under these conditions Python should look for the file brian.py in
the folders specified in the
Pythonpath). However, this does not work, but gives : "Can't open
file... No such file or directory".
The PYTHONPATH variable is used by the interpreter to augment the set of
locations to search for *imported* modules. It isn't used in locating
the script from the command line. However, you might find that your
installation has set .py up to be executed by the Python interpreter
using the pathext mechanism, in which case you can just give the
script's name and it will be found if it's somewwhere on your PATH (not
your PYTHONPATH).
I have not found further info availlable on bulletin boards on the
internet, so if anybody can post
the solution here, that would help me out.
Well, you could have tried the FAQ, but I don't know off the top of my
head whether that explains things. [Pauses to re-read
http://www.python.org/doc/faq/windows/]. Well, some useful things are
covered there, but it doesn't answer your question.

Since the -m option runs the code of a module you will probably find that

python -m brian

will do what you expect.

regards
Steve
 
S

Steve Holden

Francesco Bochicchio wrote:
[...]
AFAIK, PYTHONPATH only works for the imported modules. For the main
module, you have to do give the full path.
OR you could try out the new flag -m, which allows to run directly a
module from the standard library and - I guess - also user modules if
PYTHONPATH is set correcltly. So try from a "DOS Box" the command:

"c\python26>python -m brian.py"
Note that you need to give the *name* of the module to the -m option, so
that should be brian, not brian.py. E.g.:

$ python -m StringIO
File length = 1001
First line = 'SYSTEM:*:18:544:,S-1-5-18::\n'
Position = 28
Second line = 'LocalService:*:19:544:U-NT
AUTHORITY\\LocalService,S-1-5-19::\n'
Read 8 more lines
File length = 1001
Truncated length = 500

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top