使用gevent模块创建协程代码时报错:

pydev debugger: process 10700 is connecting

Connected to pydev debugger (build 183.5912.18)
Traceback (most recent call last):
  File "F:\Program Files\JetBrains\PyCharm 2018.3.5\helpers\pydev\pydevd.py", line 1741, in <module>
    main()
  File "F:\Program Files\JetBrains\PyCharm 2018.3.5\helpers\pydev\pydevd.py", line 1735, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "F:\Program Files\JetBrains\PyCharm 2018.3.5\helpers\pydev\pydevd.py", line 1135, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "F:\Program Files\JetBrains\PyCharm 2018.3.5\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/Administrator/PycharmProjects/django_machine_learning/DeepLearning_In_Django/algorithms/gevent.py", line 1, in <module>
    import gevent
  File "C:\Users\Administrator\PycharmProjects\django_machine_learning\DeepLearning_In_Django\algorithms\gevent.py", line 17, in <module>
    th1 = gevent.spawn(work1)
AttributeError: module 'gevent' has no attribute 'spawn'

Process finished with exit code 1

或者:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "F:\Program Files\JetBrains\PyCharm 2018.3.5\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "F:\Program Files\JetBrains\PyCharm 2018.3.5\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/Administrator/PycharmProjects/django_machine_learning/DeepLearning_In_Django/algorithms/gevent_test2.py", line 11, in <module>
    gevent.joinall([
AttributeError: module 'gevent' has no attribute 'joinall'

问题原因:

当前使用的是python3.6版本,gevent为1.2

AttributeError: module 'gevent' has no attribute 'spawn'或者module 'gevent' has no attribute 'joinall'

解决方式:

1.pip uninstall gevent

2.pip uninstall greenlet

2.pip install gevent

AttributeError: module 'gevent' has no attribute 'spawn'或者module 'gevent' has no attribute 'joinall'

安装gevent包时会自动安装greenlet,再次执行代码可以运行

3.将相同的代码复制到另外一个app文件夹下的py文件中,执行正常(可能是本人项目的文件路径环境有问题)

 

相关文章:

  • 2021-09-09
  • 2021-10-09
  • 2021-12-13
  • 2021-06-06
  • 2021-07-27
  • 2021-05-07
  • 2022-01-23
  • 2021-08-17
猜你喜欢
  • 2021-11-14
  • 2021-09-15
  • 2021-12-19
  • 2021-11-02
  • 2021-11-28
  • 2021-08-27
  • 2021-10-09
相关资源
相似解决方案