简体   繁体   中英

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,
)

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 (eg 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__']

You can also define the version in the __init__.py of your package like:

__version__ = "1.1.0"

Then, instead of importing __version__ in your setup.py , you can read the init .py and exctract the version.

Actually, this is the solution proposed in the official Python guides:

https://packaging.python.org/guides/single-sourcing-package-version/

Another option could be using versioneer package (pandas uses it).

versioneer uses Git tags to create the version value.

Steps

Step 0: Use git tags

Versioneer uses yout Git tags.

Step 1: Install versioneer

pip install versionner

Step 2: Execute versioneer

versioneer install

Step 3: Follow the versioneer instructions

Versioneer will ask you to do some changes in your setup.py and setup.cfg.\\

In the setup.py you'll have to add something like:

import versioneer

setup(
    version=versioneer.get_version(),
    cmdclass=versioneer.get_cmdclass()
)

And in setup.cfg:

[versioneer]
VCS = git
style = pep440
versionfile_source = your_project_name/_version.py
versionfile_build = your_project_name/_version.py
tag_prefix = v
parentdir_prefix = 

Note : In the example I set "tag_prefix = v" because I like tagging like: v0.1.0, v1.0.0 and so on

After that, try:

python setup.py version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM