PYTHONPATH?

D

Dr. Pastor

Several Documents about Python
refer to PYTHONPATH.
I could not find such variable.
(Python 2.4.2, IDLE 1.1.2, Windows XP)
How should/could I nominate a Directory to be
the local Directory?
Thanks for any guidance.
 
D

Diez B. Roggisch

Dr. Pastor said:
Several Documents about Python
refer to PYTHONPATH.
I could not find such variable.
(Python 2.4.2, IDLE 1.1.2, Windows XP)
How should/could I nominate a Directory to be
the local Directory?
Thanks for any guidance.

It's a so called environment-variable. You can set these in some obscure
windows dialog in the system-preferences on a per-system or per-user base.
Or you start using cygwin (lots of good other reasons for that), and do

export PYTHONPATH=/whatever

Diez
 
M

Magnus Lycka

Dr. Pastor said:
Several Documents about Python refer to PYTHONPATH.

If you need to import libraries into Python, that don't reside in the
standard locations in your Python installation, you need to define
a PYTHONPATH environment variable in the operating system, which
points out this directory.

Defining this is done in the same way as defining PATH etc.
I could not find such variable.

Do you need it for anything?
(Python 2.4.2, IDLE 1.1.2, Windows XP)
How should/could I nominate a Directory to be the local Directory?

import os
os.chdir('c:/somedir')

Another way is to start python from there, e.g. from the
command prompt (nothing beats a command prompt!) you would do:

cd some\local\directory
python myscript.py (... or just python ...)

Note that backslash in a Python string literal denotes an escape
sequence. In Python 'c:\temp' means 'c' ':' tab 'e' 'm' 'p', since
'\t' is the escape sequence for a tab. You can use 'c:/temp' (ok
for Windows APIs) r'c:\temp' (r for raw string, i.e. don't use
escape sequences) or 'c:\\temp' (\\ is the escape sequence for
backslash).

Also note, that the way to use libraries from an arbitrary
directory without setting PYTHONPATH, is not with os.chdir,
but by doing this:

import sys
sys.path.append('c:/somedir')
 
T

Tombo

Said obscure dialog is here:
My Computer > Properties > Advanced (tab) > Environment Variables

You probably want a new system variable.

You can check the value by starting a new terminal window and typing:

echo %PYTHONPATH%

Cheers
Tombo
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top