[Tutor] env variable

Alan Gauld alan.gauld at btinternet.com
Wed Jun 4 00:23:09 CEST 2008


"james collins" <collinsjames9 at gmail.com> wrote

> home directory in a folder which i called python, my IDLE does not
> recognize the script which i am trying to import, here is a sample
> session in my IDLE:

You need to set PYTHONPATH not PATH

PATH tells the OS where to find executables like python

PYTHONPATH tells Python where to find modules to import

> one solution i was told about which worked was to type in the
> following code when i start my IDLE:
>
> import sys
> sys.path.append( "/users/jamescollins/python/" )

Thats fine as a temporary measure but you would need to do
it in every script. As you discovered!

> "Or you can modify python path by setting PYTHONPATH env variable. 
> In
> bash shell:
> $ export PYTHONPATH=.:$HOME/python:$PYTHONPATH

Note this says "in the bash shell"
The $ at the beginning is the conventional way of describing
prompt displayed by bash. You do not type it in.

> $ export PYTHONPATH=.:$HOME/python:$PYTHONPATH
>
> but when i went into my python IDLE i got error messages to the 
> extent
> that my IDLE couldn't find the scripts i was trying to import. one
> thing i will mention is that i added the above line exactly as it is
> written above.

Enter the line in your profile as:

export PYTHONPATH=.:$HOME/python:$PYTHONPATH

Which tells Python to look for modules in the current directory(the 
dot),
in the python folder of your home directory ($HOME/python) and in
whatever folders were already set up ($PYTHONPATH)

The 'export' simply makes the setting visible outside of the
profile script.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list