2

I've create a command in app/management/commands and this command was working fine. I'm unable to run this command now. I'm getting the following error:

Unknown command: 'my_custom_command_name'

I'm using a virtual env. I don't see this in list of commands when I type pythong manage.py. I've this app installed in my settings and It was working previously

4
  • 1
    check if the following files exists: app/__init__.py app/management/__init__.py app/commands/__init__.py The manager might not be able to import those modules. Commented Nov 8, 2012 at 14:07
  • if you go to you django shell ./manage.py shell com you do an import app ? and does your app/ contains any models.py file? Commented Nov 8, 2012 at 14:15
  • And you're running python manage.py with the virtualenv activated? And the app is in the python path? Commented Nov 8, 2012 at 14:31
  • 2
    is your app still in INSTALLED_APPS? Commented Nov 8, 2012 at 14:47

3 Answers 3

8

Sufficient conditions:

1) The management command can be imported by:

$ python manage.py shell
>>> from yourapp.management.commands import yourcommand

(If it can't be imported then you probably easily get more details about the specific import problem. An answer can be eventually much easier searched or it is usually very trivial.)

2) The app implementing a management command for Django should be installed as a directory with individual files, not compressed into egg file. You can use the keyword parameter zip_safe=False in setup.py for preventing zipped installation. (This parameter is frequently not necessary if the False value is recognized correctly by autodetection. So it is even more surprising in other cases.)

Sign up to request clarification or add additional context in comments.

2 Comments

For more fine-grained debug where the problem is you can try the imports one at a time. "import yourapp", "import yourapp.management", "import yourapp.management.commands".
Yes, I summarized the first condition the shortest possible way because wasimbhalli confirmed the question about correct imports yet.
1

That's really weird. When I tried to run:

$ python manage.py shell 

I got the following error:

Error: cannot import name urandom

I searched for the error and found that I need to recreate my virtual env so I used the following command:

virtualenv /path/to/my/virtualenv

and then I was able to use django commands or my custom command the usual way :s

Comments

0

Sometimes this can happen if you haven't added your app to

INSTALLED_APPS = [ 'app', ]

in settings.py

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.