开发者

Unresolved import in PyDev in package __init__

This is really a trivial problem, but it's driving me crazy.

I created an essentially default PyDev project (PyDev 2.2.2, Eclipse 3.7.0) using the src folder option, so now I have something like this:

mylib [project]
    src [folder]
        mylib [package]
            __init__.py
            mymod.py

So now I want to import mymod in __init__, so my __init__.py looks like this:

import mylib.mymod

The problem is that this generates an "Unresolved import" message in the PyDev editor window for __init__.py, yet it works in the console, and it works when I run the code.

My only guess here is that the code analyzer is parsing the import using a working directory of src/mylib (instead of just src), which isn't helpful at all, since anyone who uses this library won't be doing this.

I think what I'm doing here is pretty common, but PyDev isn't liki开发者_如何学编程ng it. Is there a way to change the working directory the code analyzer uses? Or am I doing something else that's non-standard?


I have to take a look at the PyDev source, but it does seem weird that it works in Python (i.e.: inside the package mylib you're importing the mylib package again, so, it seems to me it'd be a cyclic import -- I believe that the proper way of doing it should be using a relative import... i.e.: "from . import mymod" in this case).

Anyways, if it works in Python, PyDev should recognize it too, so, I'll take a look at it :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜