#2264·rq

Simple example cannot retrieve the imported function `AttributeError: module 'module_name' has no attribute 'filename'`

Author: brunolnettoCreated Jun 12, 2025Updated Aug 17, 2026

I wrote the simple example you provide on the README on 2 files, below:

src/main.py

python
from redis import Redis
from rq import Queue

from lab.utils import count_words_at_url

queue = Queue(connection=Redis())

job = queue.enqueue(count_words_at_url, 'http://nvie.com')

print(f"Job {job.id} enqueued. Check its status at: {job.get_status()}")

./src/utils.py

python
import requests

def count_words_at_url(url):
    """Just an example function that's called async."""
    resp = requests.get(url)
    return len(resp.text.split())

I added a file __init__.py as well to the folder. In a terminal tab, I run rq worker --with-scheduler from folder above folder src, and on the the other tab, I run command python -m main.py. The queue is able to retrieve the task, but cannot resolve the import, as shown below. What can it be? Thanks in advance

08:01:30 default: lab.utils.count_words_at_url('http://nvie.com') (2230e6c3-d011-4fc9-ab68-53ed97ceed07)
08:01:30 [Job 2230e6c3-d011-4fc9-ab68-53ed97ceed07]: exception raised while executing (lab.utils.count_words_at_url)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/rq/utils.py", line 118, in import_attribute
    attribute_owner = getattr(module, attribute_owner_name)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'lab' has no attribute 'utils'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/rq/worker.py", line 1431, in perform_job
    rv = job.perform()
         ^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/rq/job.py", line 1280, in perform
    self._result = self._execute()
                   ^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/rq/job.py", line 1317, in _execute
    result = self.func(*self.args, **self.kwargs)
             ^^^^^^^^^
  File "/usr/lib/python3/dist-packages/rq/job.py", line 425, in func
    return import_attribute(self.func_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/rq/utils.py", line 120, in import_attribute
    raise ValueError('Invalid attribute name: %s' % attribute_name)
ValueError: Invalid attribute name: count_words_at_url