Search code examples
pythonpycharmdependencieslocustmodulenotfounderror

locust run showing ModuleNotFound for Python module


Follow-up from earlier question here

Running a locust (locust.io) script from the command line.

locust calls main.py which has the following imports:

from locust import HttpUser, between, task
from StreamLoader.stream_generator import *    # thought this brings in everything

Packer.py has these imports:

from multipledispatch import dispatch
from PackedItem import PackedItem

StreamGenerator.py has:

import hashlib
from StreamLoader.Packer import Packer
from aes_encryption import AesEncryption

I now see a missing module error:

  File "C:\Users\guyl\PycharmProjects\engine-load-tests\engine_load_tester_locust\main.py", line 2, in <module>
    from StreamLoader.stream_generator import *
  File "C:\Users\guyl\PycharmProjects\engine-load-tests\StreamLoader\stream_generator.py", line 2, in <module>
    from Packer import Packer
ModuleNotFoundError: No module named 'Packer'

For clarity, I am running the code from locust which calls the Python code as depicted here.

enter image description here

Here's the file structure: enter image description here


Solution

  • Placed periods (full stops) before the package names in the import statements.

    I then was able to run the locust script from within PyCharm.

    Running from the DOS shell, I was able to accomplish the same by first running

    <project directory>\venv\Scripts\activate