我不能 运行 locust on pycharm 它在错误中说

I cannot run locust on pycharm it says in the error

我想寻求有关此错误的帮助。仅供参考,我有两个版本的 python,它们是 python 2.7 和 3.9 但我使用 3.9 到 运行 locust。已经在环境变量中设置了路径,在 pycharm.

中设置了 python 解释器

我是负载测试的新手,我已经搜索过解决方案,但 none 有效。因此,如果您对如何解决此问题有想法。我将衷心感谢您的帮助。谢谢。

这是错误:

    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: Traceback (most recent call last):
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: File "c:\python27\lib\runpy.py", line 
    174, in _run_module_as_main
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr:
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: "__main__", fname, loader, pkg_name)
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: File "c:\python27\lib\runpy.py", line 
    72, in _run_code
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr:
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: exec code in run_globals
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: File 
    "C:\Python27\Scripts\locust.exe\__main__.py", line 9, in <module>
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: File "c:\python27\lib\site- 
    packages\locust\main.py", line 428, in main
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr:
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: docstring, locusts = 
    load_locustfile(locustfile)
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: File "c:\python27\lib\site- 
    packages\locust\main.py", line 397, in load_locustfile
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr:
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: imported = 
     __import_locustfile__(locustfile, path)
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: File "c:\python27\lib\site- 
    packages\locust\main.py", line 371, in __import_locustfile__
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr:
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: imported = 
    imp.load_source(os.path.splitext(locustfile)[0], path)
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: File 
    "C:\Users\PycharmProjects\LoadTest\seq1creation.py", line 8, in <module>
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr:
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: from locust import HttpUser, 
    SequentialTaskSet, constant, task
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: ImportError
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: :
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr: cannot import name HttpUser
    [2021-07-06 17:14:43,209] EFSI20210122/ERROR/stderr:

检查你的 locust 版本 (locust -V)。

看起来你是 运行 一个旧的 (0.x) 版本,很可能是最后一个支持 python 2 的版本。

可能根本原因是您以某种方式为 2.7 环境安装了 locust。