How to import a simple class in working directory with python?
<p>I read various answer (<a href="http://stackoverflow.com/questions/16981921/relative-imports-in-python-3">relative import</a>), but none work to import a simple class. I have this structure:</p>

<pre><code>__init__.py   (empty)
my_script.py
other_script.py
my_class.py
</code></pre>

<p>I want to use <strong>my_class.py</strong> in both script (<strong>my_script.py</strong> and <strong>other_script.py</strong>). Like all answer suggest, I just use:</p>

<pre><code>from .my_class import My_class
</code></pre>

<p>but I always get</p>

<blockquote>
  <p>SystemError: Parent module '' not loaded, cannot perform relative import</p>
</blockquote>

<p>I am using <strong>Python 3.5</strong> and <strong>PyCharm 2016.1.2</strong>. Does I need to configure the <code>__init__.py</code>? How can I import a simple class?</p>

<p><strong>Edit</strong></p>

<p>All the files are in the working directory. I just use the Pycharm to run and I wasn't having problem until try to import the class. </p>

<p>Ensure that your current working directory is <strong><em>not</em></strong> the one that contains these files.   For example, if the path to <code>__init__.py</code> is <code>spam/eggs/__init__.py</code>, make sure you are working in directory <code>spam</code>âor alternatively, that <code>/path/to/spam</code> is in <code>sys.path</code> and you are working in some third place. Either way, do not attempt to work in directory <code>eggs</code>.   To test your code, you say <code>import eggs</code>.</p>

<p>The reasoning is as follows.  Since you're using <code>__init__.py</code> you clearly want to treat this collection of files as a <a href="https://docs.python.org/2/tutorial/modules.html#packages" rel="nofollow">package</a>. To work as a package, a directory must fulfill both the following criteria:</p>

<ol>
<li>it contains a file called <code>__init__.py</code></li>
<li>its <strong><em>parent</em></strong> directory is part of the search path (or the parent directory is your current working directory); in effect, a package directory must masquerade as a file, i.e. be findable in exactly the same way that a single-file module might be found.</li>
</ol>

<p>If you're working <em>inside</em> the package directory you may not be fulfilling criterion 2.   You can do a straightforward <code>import my_class</code> from there, certainly, but the "relative import" thing you're trying is a feature that only a fully-working package will support.</p>

python pycharm