7

I'm trying to get running the Huey task queue for python (it's a Celery alternative) and I'm stuck with starting the consumer with main.Configuration (as it's written in the tutorial). I know the huey_consumer is looking for the configfile somewhere in the python, but I cannot get it working according to the tutorial and I don't know why I should write a config file and load it as a module (instead of a file).

When I run huey_consumer.py main.Configuration it returns Unable to import "main".

Huey have this issue written in their common pitalls too, but it's not really helping either.

If there is somebody using Huey, please help me.

Dacav
  • 13,590
  • 11
  • 60
  • 87
Jakub Žitný
  • 962
  • 1
  • 9
  • 38

3 Answers3

2

I had the same problem and solved it by adding the directory containing main.py to the PYTHONPATH. There was no need to copy huey_consumer.py

adg
  • 552
  • 1
  • 6
  • 17
0

So the way this works is it tries to import the module "main". It would be equivalent to opening up a python shell and running:

>>> from main import Configuration

Perhaps you can reply with more information about your environment, the layout of your files, what you're running, etc.

coleifer
  • 24,887
  • 6
  • 60
  • 75
  • Thanks for reply. I was trying to complete [the tutorial](http://huey.readthedocs.org/en/latest/getting-started.html) section `Trying it out yourself`. I installed huey, I wrote the three files config.py, commands.py and main.py and I was trying to start the consumer so I believed the client should be started with the config.py. But then, what I'm supposed to do? Make a python module called from the conig.py? Wouldn't it be better to just start a client with a reference to configfile? – Jakub Žitný Feb 19 '13 at 01:52
  • Think of "main" as a container that serves as an entry-point into your application. Main will import all your commands *and* your configuration. So that is why, when you start the consumer you need to point it at main. This is all covered in the docs. If you can provide more info about the layout of your files I might be able to help. Did you try opening a python shell and importing main as I suggested? – coleifer Feb 20 '13 at 14:04
0

I think you need to add an __init__.py file to the folder that contains main.py, ... else you cannot import anything as python will not consider this folder as a module.

What's the difference between a Python module and a Python package?

See comment by giulio-piancastelli

Community
  • 1
  • 1
n3storm
  • 704
  • 8
  • 21
  • 1
    I was wrong. At this moment /usr/local/bin/huey_consumer.py doesn't load modules at all, even with __init__.py huey_consumer.py must be copied to the directory you have your files: main.py, config.py, command.py else it won't work. I have notified of the issue at Github. – n3storm Mar 15 '13 at 13:15