title: Make Pycharm see packages in subdirectory, without adding it as a source root
body: <p>Let's say I have a project with structure</p>
  
  <pre><code>parent/
      one.py
      sub/
          two.py
          three.py
  </code></pre>
  
  <p>Where file <code>two.py</code> is</p>
  
  <pre><code>x = 42
  </code></pre>
  
  <p>And <code>three.py</code>:</p>
  
  <pre><code>from two import x
  
  print(x)
  </code></pre>
  
  <p>The import statement in <code>three.py</code> will work correctly as these files lie in the same directory, but the PyCharm will mark the import as an <strong>Unresolved reference</strong>:</p>
  
  <p><a href="https://i.stack.imgur.com/UciY2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UciY2.png" alt="Screenshot"></a></p>
  
  <p>One way to fix that is to ask PyCharm to mark the directory <code>sub</code> as the sources root. But then the files inside <code>sub</code> will be visible to all the other files in the project, e.g. in <code>one.py</code>. But I would like to avoid this.</p>
  
  <p>The other way would be to write imports as <code>import sub.two</code>. which I do right now in my project. But this is quite annoything since I have a deep folder structure.</p>
  
  <p>Is there any other way to do it?</p>
  
  <p><strong>UPD:</strong>
  Changing import statement to</p>
  
  <pre><code>from .two import x
  </code></pre>
  
  <p>Would cause a error</p>
  
  <pre><code>ModuleNotFoundError: No module named '__main__.two'; '__main__' is not a package
  </code></pre>
  
  <p>Also I observed, if I try to use relative import from a parent directory, e.g.</p>
  
  <pre><code>from ..one import y
  </code></pre>
  
  <p>I am getting</p>
  
  <pre><code>ValueError: attempted relative import beyond top-level package
  </code></pre>
  
  <p>So I would suspect this has something to do with my project configuration and relative imports work from the top-level directory of the project. I will try to dig in deeper, but I would still appreciate some answer from those, who might have already encountered this problem.</p>