DEAP / deap

Distributed Evolutionary Algorithms in Python
http://deap.readthedocs.org/
GNU Lesser General Public License v3.0
5.87k stars 1.13k forks source link

Seeking Help for "ValueError: too many values to unpack" Issue in Python Program #736

Open ZhShihang opened 11 months ago

ZhShihang commented 11 months ago

Hello everyone,

I hope you're doing well. I am a Python program user and have recently encountered a challenging issue while working on my project. I am getting the following error, and despite trying various solutions, I haven't been able to resolve it:

Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm 2022.3.3\plugins\python\helpers\pydev\pydevd.py", line 1496, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm 2022.3.3\plugins\python\helpers\pydev_pydev_imps_pydevexecfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:\Users\main.py", line 786, in algorithms.eaMuPlusLambda(population, toolbox, mu=100, lambda=200, cxpb=0.7, mutpb=0.2, ngen=ngen, stats=None, File "C:\deap\algorithms.py", line 316, in eaMuPlusLambda offspring = varOr(population, toolbox, lambda_, cxpb, mutpb) File "C:\deap\algorithms.py", line 239, in varOr ind, = toolbox.mutate(ind) ValueError: too many values to unpack (expected 1)

I've tried several approaches, but the issue persists. I'm reaching out to the community for assistance. If any developers here have insights into the possible causes of this "ValueError," or if you've encountered a similar situation before, I would greatly appreciate any advice or solutions you can offer. Thank you so much for your time and assistance!

fengyangsun commented 11 months ago

It seems you return too many variables with the function. You could try this line as: ind = toolbox.mutate(ind) Note: without the comma Another thing is, you may have already defined your own mutate function without the comma, in which case you need to add it in function definition so you don't have to change other things.