[Tutor] newbie OSX module path question

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Feb 15 02:41:21 CET 2005



On Mon, 14 Feb 2005, Mike Hall wrote:

> > Can you show us what your sys.path looks like?  Just do a
> > cut-and-paste so we can quickly validate it for you.
>
> Thanks for the response. Here's a paste of what sys.path returns. The
> first listing is the path inside of environment.plist:
>
> ['', '/Local_HD/Users/mike/Documents/pythonModules',
> '/Users/tempmike/Documents/pythonModules',
> '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python23.zip',
> '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3',
> '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/plat-darwin',
> '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/plat-mac',
> '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/plat-mac/lib-scriptpackages',
> '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/lib-tk',
> '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/lib-dynload',
> '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/site-packages']
>
> > Can you show us the exact thing you're typing, as well as the literal
> > error that Python shows?
>
> I will attempt to import using 'import' followed by file name. Example:
>
> import module1
>
> The error returned will be:
>
> ImportError: No module named module1


[Meta: Please keep python-tutor in CC, so that all of us on the mailing
list can help you.]


Hi Mike,

Ok, can you do this at the Python prompt?

###
>>> import glob
>>> print glob.glob('/Local_HD/Users/mike/Documents/pythonModules/*.py')
###

Copy and paste the output you see.

If things go wrong, then we will have a good focus point to debug the
problem.  But if things go right --- if you see a bunch of Python module
files --- then I will be stuck and will have to think of something else.
*grin*



> > Do you have problems doing an import if your modules's directory is
> > the current working directory?
>
> Funny you should mention that. After posting to this list, I tried
> cd'ing over to the dir I created for modules, and then launched Python.
> My modules can indeed be imported using this method.  But I'm still
> curious as to why I cannot get a successful import (when I'm not within
> my work dir) when the path is visibly defined within the sys.path
> variable? Thanks very much.

Ok, so there appears to be nothing wrong with the modules themselves or
with importing them when they're in the current working directory. We
should then focus on sys.path itself, since that's the mechanism Python
uses to lookup modules that aren't in the current directory.

For the moment, I'll assume that there's something funky with the
pathname.  As mentioned earlier, it could be as subtle as a
case-sensitivity issue.  The glob statement above will help us check to
see if Python can see those files, at least.


Best of wishes to you!



More information about the Tutor mailing list