[Tutor] env variable

james collins collinsjames9 at gmail.com
Tue Jun 3 21:39:18 CEST 2008


have a question about setting up an env. variable.
i own a macbook pro laptop running mac os x 10.5.2.
i downloaded MacPython 2.5.
my problem is that when i go to run a script which i have saved in my  
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:

 >>> import script1

Traceback (most recent call last):
   File "<pyshell#0>", line 1, in <module>
     import script1
ImportError: No module named script1

i was told that i have to set the env. variable path, so my computer  
knows where to find the scripts i am working on.
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/" )

this worked for me, but i thought there should be a more elegant way  
to import scripts i am working on, than to have to write this code in  
each time i want to run a script.

i also was told of a way to modify my python path env variable, and  
this is what i want to do, but i am unsure of how to do this? I was  
told:

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

Usually one does it by including the above line in .bash_profile file."

i went into terminal, which is mac os x command line, and  
opened .bash_profile file into textedit. the file was hidden but i was  
able to open it, i then tried adding the line which i was told to add:

$ 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.
can anyone help me set up the path so my computer looks in a certain  
directory for the scripts i am working on?



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080603/d49abb24/attachment.htm>


More information about the Tutor mailing list