Moving python package without messing internal imports
<p>I wrote a python package that includes many modules. The modules import each other within the package.
Now after it is complete I wish to move my package inside a different package as a subdirectory. But I can't do it because now all the imports get errors because they can't find the modules on their new path.</p>

<p>For example -</p>

<p>In module <code>my_package.a</code> I have:</p>

<pre><code>x = 5
</code></pre>

<p>In module <code>my_package.b</code>:</p>

<pre><code>from my_package.a import x 
print x
</code></pre>

<p>Before I did: <code>from my_package import b</code>, and now I wish to do <code>from tools.my_package import b</code>, and get the same result.</p>

<p>What is the right way to change a package logic path without having to add the new path to <code>sys.path</code>?</p>

<p>I would use relative imports internally:</p>

<pre><code>from .a import x
</code></pre>

<p>If your module is self-contained, you can relocate it without issues if it uses relative imports.</p>

python import packages