[Tutor] adding a new folder to Python's importable modules search path

Kent Johnson kent37 at tds.net
Mon Nov 26 04:09:44 CET 2007


tpc247 at gmail.com wrote:
> Dear fellow Python enthusiasts,
> 
> I trust your Thanksgiving holiday has been a relaxing one.  A quick 
> question for you: I have a script that attempts to import my_module from 
> a folder that is not in Python's importable modules search path.  In my 
> script, that I run from the command line, I have the following lines:
> 
> import os
> import sys
> 
> PATH_TO_MODULE = os.path.join('path', 'to', 'my', 'module')
> sys.append(PATH_TO_MODULE)

Should be sys.path.append(...)

Kent

> 
> import my_module
> 
> When I attempt to run the script, I get the following error message:
> 
> ImportError: No module named my_module
> 
> In Python IDLE when I perform the aforementioned steps in the order 
> indicated I can import my_module successfully.  My assumption is 
> Python's importable modules search path is in sys.path.  In both cases I 
> identify the path to the folder containing my module, I append said path 
> to sys.path, and when I attempt to import my_module by either running 
> from the command line or in IDLE, I get different behavior.  I read the 
> information here again:
> 
> http://docs.python.org/tut/node8.html
> 
> so I believe I am doing everything correctly.  Am I doing something wrong ?
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list