Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7367] pkgutil.walk_packages fails on write-only directory in sys.path

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Nov 20, 2009, 1:46 PM

Post #1 of 2 (168 views)
Permalink
[issue7367] pkgutil.walk_packages fails on write-only directory in sys.path

Ned Deily <nad [at] acm> added the comment:

>I initially came across the error when attempting to get a modules list
>and was returned a list of errors. One of them was the [errno 13].

OK, now that makes more sense!

The problem is that somehow you had a write-only directory ("~/Public/Drop
Box") on your python module search path. If you type the following commands
in IDLE or in the interpreter:

import sys
sys.path

you will likely see the "Drop Box" directory in the list of paths (assuming
things haven't changed).

When you run the "modules" help command, the python help module, pydoc, uses
the pkgutil module to search the entire list of directories in sys.path and
attempts to import each package it finds in each directory to print the
module's help information (btw, there are no separate help files).

While the pkgutil.walk_packages function tries to handle most errors, it
isn't prepared to handle the case of a write-only directory on sys.path and
that's the root cause of the error of the error you saw. The following test
case demonstrates the problem:

import os, pkgutil, sys

dirname_wo = os.tempnam()
os.mkdir(dirname_wo, 0222) # write permission only
try:
sys.path.insert(0, dirname_wo)
def onerror(pkgname):
print('onerror called for package %s' % pkgname)
for importer, modname, ispkg in pkgutil.walk_packages(onerror=onerror):
print modname
finally:
os.rmdir(dirname_wo)

The long-term solution is to have pkgutil.walk_packages protect itself
against os.listdir errors. A patch is needed for that.

In your case, though, you should check for and remove whatever is adding
"Drop Box" to your Python sys.path. Perhaps you have an out-of-date export
of PYTHONPATH in a shell profile (.bash_profile, etc)? Or something left
over in a site-packages pth file (perhaps by trying to install a package
from the "Drop Box" directory)? By changing the permissions as you did, you
worked around the problem but that's not the right solution and you could be
compromising the security of your drop box file.

----------
components: +Library (Lib) -IDLE
title: IDLE OSError [errno 13] permission denied accessing help files -> pkgutil.walk_packages fails on write-only directory in sys.path
versions: +Python 2.7, Python 3.1, Python 3.2

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7367>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 20, 2009, 1:54 PM

Post #2 of 2 (145 views)
Permalink
[issue7367] pkgutil.walk_packages fails on write-only directory in sys.path [In reply to]

Ned Deily <nad [at] acm> added the comment:

More precisely: you should check for and remove whatever is adding
"Drop Box" or a directory within it to your Python sys.path.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7367>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.