Search code examples
pythonimportpython-importimporterrorlocust

ImportError: cannot import name 'HttpUser' from 'locust'


I am trying the locust quick start in my mac and I am getting this error for any import I try. I have python 2.7 and python 3.7 installed in my machine but i use only python 3.7

➜  ~ python -V
Python 2.7.16
➜  ~ python3 -V
Python 3.7.5

my locust version is: 1.4.3

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/xxxxx/xxxxx/xxxxx/xxxxx/locust.py", line 3, in <module>
    from locust import HttpUser, task, between
ImportError: cannot import name 'HttpUser' from 'locust' (/Users/xxxxx/xxxxx/xxxxx/xxxxx/locust.py)```

Solution

  • It seems that you have named the locust file locust.py instead of locustfile.py as quick-start suggest. I think that perhaps that will be causing you to fail the imports from the same file.

    Can't tell properly without a way to test it or more details related to how you are running locust.

    Try changing the filename of the locust test scenarios