Note that there are some explanatory texts on larger screens.

plurals
  1. POPython strange import behavior: import x.y works, from x import y doesn't
    text
    copied!<p>I am having a simple directory structure, like that:</p> <pre><code>MyProject --main.py --lib #that's a directory/package ----__init__.py ----view.py ----common_lib.py ----other irrelevant modules... </code></pre> <p>In main.py:</p> <pre><code>from lib import view </code></pre> <p>causes the following error:</p> <pre><code>ImportError: cannot import name view </code></pre> <p>If instead, I write it like:</p> <pre><code>from lib.view import * </code></pre> <p>This import passes successfully, but next failure happens in view.py, in that:</p> <pre><code>from common_lib import Comments, Locations, ScreenData, ProgressSignal </code></pre> <p>causes:</p> <pre><code>ImportError: No module named 'common_lib' </code></pre> <p>And as it appears from the directory structure, common_lib.py resides in the same directory as view.py, how can it happen that it cannot be found? How does it come that 'from x import y' doesn't work, and 'from x.y import *' works? '<code>__init__.py</code>' is completely empty BTW. And I am using Python 3.3 32-bit.</p> <p>What is more annoying, this same program worked 2 days ago.I was testing some code in IDLE and when I thought the code was ready to include in the project, pasted it into PyDev, I was shocked by this error. I changed nothing about my directories or modules.</p> <p>Also, still more strangeness, running view.py and common_lib.py as standalone (without being imported) runs just fine. It should produce the error if any issues really existed.</p> <p>Thanks. Any advice is highly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload