pythonpython-3.xsetup.py

setup.py don't installing the requirements


I'm did a python library, it's my first python library published on pypl and github

The library works very well, but the setup() doesn't.

When I install it by pip install, it dowloand the appfly package but do not install the requirements: Flask,flask_cors, Flask-SocketIO and jsonmerge. So I need install it by myself. If I install the dependencies myself, it's works very well, but i think it's the wrong way to use a python library right?

here is my setup.py file, I'm doing something wrong?

from setuptools import setup, find_packages
from appfly import __version__ as version

with open('README.md') as readme_file:
    readme = readme_file.read()

# with open('HISTORY.md') as history_file:
#     history = history_file.read()

requirements = [
    'Flask==1.0.2',
    'flask_cors==3.0.6', 
    'Flask-SocketIO==3.0.2',
    'jsonmerge==1.5.2'
]

setup(
    author="Italo José G. de Oliveira",
    author_email='italo.i@live.com',
    classifiers=[
        'Natural Language :: English',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
    ],
    description="This pkg encapsulate the base flask server configurations",
    install_requires=requirements,
    license="MIT license",
    long_description=readme,
    include_package_data=True,
    keywords='appfly',
    name='appfly',
    packages=find_packages(),
    url='https://github.com/italojs/appfly',
    version=version,
    zip_safe=False,
)

Solution

  • The reason for this error is that the setup.py imports from the package. This means that python will try importing the library while processing the setup.py (ie. before any of the dependencies get installed).

    Since you are only importing the package to get the version information, this import can be replaced with a different method.

    An easy way to do this is to include the version information directly in the setup.py, but the drawback with this is that the version is no longer single sourced.

    Other methods involve a bit of work but allow the version information to continue to be single sourced. See https://packaging.python.org/guides/single-sourcing-package-version/ for recommendations. That page has a list of options, some of which may be better suited to your package setup than others. I personally prefer option 3:

    Set the value to a __version__ global variable in a dedicated module in your project (e.g. version.py), then have setup.py read and exec the value into a variable.

    ...

    Using exec:

    version = {}
    with open("...sample/version.py") as fp:
        exec(fp.read(), version)
    # later on we use: version['__version__']