简体   繁体   English

setup.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我做了一个 python 库,这是我在pyplgithub上发布的第一个 python 库

The library works very well, but the setup() doesn't.该库运行良好,但 setup() 不行。

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 .当我通过pip install安装它时,它会下载 appfly 包但不安装要求: 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?如果我自己安装依赖项,它运行得很好,但我认为这是使用 python 库的错误方式,对吗?

here is my setup.py file, I'm doing something wrong?这是我的setup.py文件,我做错了什么?

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.此错误的原因是setup.py从包中导入。 This means that python will try importing the library while processing the setup.py (ie. before any of the dependencies get installed).这意味着 python 将在处理setup.py时尝试导入库(即在安装任何依赖项之前)。

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.一种简单的方法是将版本信息直接包含在setup.py ,但这样做的缺点是版本不再是单一来源的。

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.有关建议,请参阅https://packaging.python.org/guides/single-sourcing-package-version/ 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:我个人更喜欢选项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.将值设置为项目中专用模块中的__version__全局变量(例如 version.py),然后让 setup.py 读取并将值执行到变量中。

... ...

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:您还可以在包的__init__.py中定义版本,例如:

__version__ = "1.1.0"

Then, instead of importing __version__ in your setup.py , you can read the init .py and exctract the version.然后,您可以读取init .py 并提取版本,而不是在setup.py中导入__version__

Actually, this is the solution proposed in the official Python guides:实际上,这是官方 Python 指南中提出的解决方案:

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

Another option could be using versioneer package (pandas uses it).另一种选择可能是使用 versioneer 包(熊猫使用它)。

versioneer uses Git tags to create the version value. versioneer 使用 Git 标签来创建版本值。

Steps脚步

Step 0: Use git tags步骤 0:使用 git 标签

Versioneer uses yout Git tags. Versioneer 使用你的 Git 标签。

Step 1: Install versioneer第 1 步:安装 versioneer

pip install versionner

Step 2: Execute versioneer第二步:执行versioneer

versioneer install

Step 3: Follow the versioneer instructions第 3 步:按照 versioneer 说明进行操作

Versioneer will ask you to do some changes in your setup.py and setup.cfg.\\ Versioneer 会要求您对 setup.py 和 setup.cfg 进行一些更改。\\

In the setup.py you'll have to add something like:在 setup.py 中,您必须添加如下内容:

import versioneer

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

And in setup.cfg:在 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注意:在示例中,我设置了“tag_prefix = v”,因为我喜欢标记:v0.1.0、v1.0.0 等等

After that, try:之后,尝试:

python setup.py version

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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