Foris Kuang Foris Kuang - 3 months ago 9
Python Question

'method' object is not iterable from calling splitlines from a read method

Currently trying to setup my setup.py file for pip installation or simply python setup.py develop installation, however when I run the code, it faults saying that the method is not iterable, regarding to my read function.

The code is as follows for setup.py

from setuptools import setup, find_packages
import os

def read(filename):
with open(os.path.join(os.path.dirname(__file__), filename)) as f:
return f.read()

setup(
name='example',
version='1.0',
description='example',
url='https://github.com/example',
author='Example',
author_email='iam@example.com',
packages=find_packages,
install_requires=read('requirements.txt').splitlines(),
zip_safe=False
)


And finally the error I receive is,

Traceback (most recent call last):
File "setup.py", line 16, in <module>
install_requires=read('requirements.txt').splitlines()
File "C:\Python35\lib\distutils\core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "C:\Python35\lib\site-packages\setuptools\dist.py", line 272, in __init__
_Distribution.__init__(self,attrs)
File "C:\Python35\lib\distutils\dist.py", line 281, in __init__
self.finalize_options()
File "C:\Python35\lib\site-packages\setuptools\dist.py", line 327, in finalize_options
ep.load()(self, ep.name, value)
File "C:\Python35\lib\site-packages\setuptools\dist.py", line 161, in check_packages
for pkgname in value:
TypeError: 'method' object is not iterable

Answer

This line is missing the call parens you need:

packages=find_packages,

Change it to:

packages=find_packages(),