benwad benwad - 5 months ago 23
Python Question

Importing my package from a Django management command

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

) using
pip install --editable
, and I can successfully use shell
to import a module from that package:

in[0]: from codequal import something
in[1]: something.some_method()
out[2]: u'result'

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

File "/home/path/to/django/project/some_app/management/commands/", line 8, in <module>
from codequal import something
ImportError: cannot import name something

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

'console_scripts': [
'codequal = codequal.cli:main',

Does this prevent from the module being imported from certain places? I can't see how it would, since I can do it from shell


The problem is that your file ( has the same name that the module. You need to change one of them. I recomended the file inside the app: