pythonpiplocustmodulenotfounderrormultiple-dispatch

multipledispatch ModuleNotFoundError running from command-line


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 used pip to install multipledispatch and when I run from within PyCharm it works fine, but from the command line I get the following.

  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 StreamLoader.Packer import Packer
  File "C:\Users\guyl\PycharmProjects\engine-load-tests\StreamLoader\Packer.py", line 1, in <module>
    from multipledispatch import dispatch
ModuleNotFoundError: No module named 'multipledispatch'

Here is what I have tried so far:

  1. Add directories to the PYTHONPATH environment variable
  2. Add empty __init__.py files in each package

This all seems unnecessary if I actually pip installed the module, though.


Answer below caused me to no longer see the error with multipledispatch. However, 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. [Moderators - this question is getting quite long. Is that all right?]

enter image description here

enter image description here


Solution

  • PyCharm uses the virtual environment automatically but when you run from the command line the virtual environment isn't turned on.

    Just follow the steps:

    1. cd your_working_directory
    2. environment_name/Scripts/activate if on Windows where environment_name is the name of the PyCharm virtual environment

    Or environment_name/bin/activate if on MacOS

    -------------EDIT------------------------
    To answer the new question, try using pip freeze then see which packages are installed. Then install any dependencies which you want which are missing.