0

I want to add folders mydata1 and mydata2 in root package recursively when install my project. So I write this function in setup.py:

def gen_data_files(*dirs):
    results=[]
    for datadir in dirs:
        results.extend([(p, [os.path.join(p,f) for f in files]) for p, subdirs, files in os.walk(datadir)])
    return results

And then in setup.py:

setup(
    #...
    data_files=gen_data_files('mydata2', 'mydata2'),
    #...
)

Creating the sdist is ok: setup.py sdist upload -r mypypi

But when I install, an exception was throw: ValueError: too many values to unpack (expected 2).

I'm new in Python. So I don't know why. Can you help me in this case? Thanks!

EDIT: Those codes have the same results:

results.extend([(p, [os.path.join(p,f) for f in files]) for p, subdirs, files in os.walk(datadir)])

results.extend((p, [os.path.join(p,f) for f in files]) for p, subdirs, files in os.walk(datadir))
aviit
  • 1,957
  • 1
  • 27
  • 50

2 Answers2

0

The function should be:

def gen_data_files(*dirs):
    results = []
    for datadir in dirs:
        for p, subdirs, files in os.walk(datadir):
            results.extend((p, os.path.join(p, f)) for f in files)
    return results

Also, may I suggest using setuptools.

Gerges
  • 6,269
  • 2
  • 22
  • 44
  • I searched google many times for this and maybe I tried somethings like your link about setuptools. The tutorial in your link is quite long. Maybe I missed something so I cannot resolve the issue. – aviit Apr 19 '18 at 06:58
0

Sorry everybody, the issue is my version 5.99999. Too long. Use somethings like 6.0 fixed.

aviit
  • 1,957
  • 1
  • 27
  • 50