ImportError: cannot import name 'HttpUser' from 'locust'
Asked Answered
L

1

5

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)```
Laplante answered 23/2, 2021 at 10:31 Comment(2)
If you type into the terminal python3 -m pip list does the module show up there? Are you using python3 -m pip install to install modules?Scenography
yes, the module shows up in the list yes, I used pip3 install locust, not python3 -m pip install as i always doLaplante
T
12

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

Tay answered 23/2, 2021 at 15:58 Comment(1)
If this fixed your issue could you accept it as the answer?Scenography

© 2022 - 2024 — McMap. All rights reserved.