开发者

Package module not found in Python 2.5, but found in 2.6

I have package structure that looks like this:

  • ae
    • util

util contains a method mkdir(d开发者_StackOverflowir) that, given a path, creates a directory. If the directory exists, no error is thrown; the method fails silently.

The directory ae and its parent directory are both on my PYTHONPATH. When I try to use this method in Python 2.6, everything is fine. However, Python 2.5 gives the following error:

util.mkdir(SOURCES)
    AttributeError: 'module' object has no attribute 'mkdir'

Why is Python 2.6 able to find this module and its method with no problems, but Python 2.5 cannot?


Maybe Python 2.5 is accessing a different version of util that does not have the mkdir method.


  • do you import ae.util or import util? Either ae or its parent dir should be in PYTHONPATH, but not both
  • verify you have the right util module by running print util (will print the module's source file)


It depends where You call this method, and what Your import is. If You write:

from ae import util
util.mkdir(SOURCES)

everything should be ok.

The error occurs probably because of the difference in the import policy between Python 2.5 and 2.6.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜