[Tutor] Can't find modules at command line

Alan Gauld alan.gauld at btinternet.com
Tue Nov 3 23:04:09 CET 2009


"Christian Witts" <cwitts at compuscan.co.za> wrote
>> >>> import gun
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> ImportError: No module named gun
>> >>> 
>>
>> This file is at [/Users/sam/Documents/gun.py].  What should I do to 
>> make it visible to Python?
>>   
> In the console when you start it up you appear to be in your home 
> directory `~` but your script is in the Documents folder so you will 
> need to add Documents to your path for eg.
> from sys import path
> path.append('/path/to/script/to/be/imported')
> import gun

Or you can create/edit your PYTHONPATH environment variable
to include /Users/sam/Documents.

You do that in your ~/.bash_profile file with

export PYTHONPATH=$PYTHONPATH:/Users/sam/Documents

Note the dot before the filename...

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/





More information about the Tutor mailing list