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

使用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

解决方式:

1.pip uninstall gevent

2.pip uninstall greenlet

2.pip install gevent

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

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值