DEAP / deap

Distributed Evolutionary Algorithms in Python

Home Page:http://deap.readthedocs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

BIM4SmartHydropower opened this issue · comments

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_pydev_execfile.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!

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.