Can't find modules at command line

View: New views
3 Messages — Rating Filter:   Alert me  

Can't find modules at command line

by Sam Stout :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
I'm using Python on Mac OS X.  I usually run IDLE and get this result:

IDLE 1.2      
>>> import gun
Bang!
>>> 

However, when I try this from Terminal:

Jacks-Mac:~ Sam$ python
ActivePython 2.5.0.0 (ActiveState Software Inc.) based on
Python 2.5 (r25:51908, Mar  9 2007, 17:40:37) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 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?


_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Re: Can't find modules at command line

by Christian Witts :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sam Stout wrote:

> I'm using Python on Mac OS X.  I usually run IDLE and get this result:
>
> IDLE 1.2      
> >>> import gun
> Bang!
> >>>
>
> However, when I try this from Terminal:
>
> Jacks-Mac:~ Sam$ python
> ActivePython 2.5.0.0 (ActiveState Software Inc.) based on
> Python 2.5 (r25:51908, Mar  9 2007, 17:40:37)
> [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> 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?
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor@...
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>  
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

--
Kind Regards,
Christian Witts


_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Re: Can't find modules at command line

by Alan Gauld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Christian Witts" <cwitts@...> 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/



_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor