Importing my package from a Django management command
<p>I've written a package which was originally a command-line tool, but I've decided that for Django it should be run from a management command. I've installed my external package (called <code>codequal</code>) using <code>pip install --editable</code>, and I can successfully use <code>manage.py shell</code> to import a module from that package:</p>

<pre><code>in[0]: from codequal import something
in[1]: something.some_method()
out[2]: u'result'
</code></pre>

<p>This works fine. However, when I try to do the same thing in a management command, I run into an error:</p>

<pre><code>File "/home/path/to/django/project/some_app/management/commands/codequal.py", line 8, in &lt;module&gt;
    from codequal import something
ImportError: cannot import name something
</code></pre>

<p>Why is this? I can use other installed packages from management commands. Could it be something to do with my setup.py? I can post snippets from that if needed. Mainly I'm wondering if this part is to blame:</p>

<pre><code>    entry_points={
    'console_scripts': [
        'codequal = codequal.cli:main',
    ],
</code></pre>

<p>Does this prevent from the module being imported from certain places? I can't see how it would, since I can do it from <code>manage.py shell</code>.</p>

<p>The problem is that your file (codequal.py) has the same name that the module. You need to change one of them. I recomended the file inside the app:</p>

<pre><code>/home/path/to/django/project/some_app/management/commands/codequal.py
</code></pre>

<p>to</p>

<pre><code>/home/path/to/django/project/some_app/management/commands/codequal_utils.py
</code></pre>

python django setuptools django-management-command