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

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

我在我的 mac 中尝试使用 Locust 快速启动,但我尝试导入时遇到此错误。 我在 machine 中安装了 python 2.7 和 python 3.7,但我只使用 python 3.7

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

我的蝗虫版本是: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)```

您似乎将 locust 文件命名为 locust.py 而不是快速启动建议的 locustfile.py。我认为这可能会导致您无法从同一文件导入。

如果没有测试方法或更多与你是 运行 蝗虫有关的详细信息,就无法正确判断。

尝试更改蝗虫测试场景的文件名