如何在解压缩python软件包期间检查是否安装了requirements.txt中的库

时间:2018-09-21 16:45:29

标签: json python-3.x package

我正在构建一个pypi工具,该工具将自动从json文件和print中安装python库(无论是否安装)。 这是我的setup.py文件:

import setuptools
import pip
from subprocess import call
for package in 'requirements':
    try:
        call("pip install "+package, shell=True)
        print("Install success")
    except:
        print("Install failed for "+package)    
with open("README.md", "r") as fh:
    long_description = fh.read()
    fh.close()
setuptools.setup(
    name="json123",
    version="0.0.1",
    author="hari",
    author_email="hari@gmail.com",
    description="Auto install of python packages",
    long_description=long_description,
    long_description_content_type="text/markdown",
    classifiers=["Programming Language :: Python :: 3",],
    include_package_data=True,
    zip_safe=False,
    py_package=['json123'],
    entry_points='''
        [console_scripts]
        json123=json123:main
    ''',
    )

json123.py是将从json文件中获取“依赖项”并将其复制到requirements.txt(该程序创建了requirements.txt)的脚本。

import json
def main():
    f = open( "package.json" , "rb" )
    d = json.load(f)
    f.close()
    with open("requirements.txt", "w+") as fb:
        for i,j in zip(d["dependencies"].keys(), d["dependencies"].values()):
            line = "{}=={}\n".format(i, j.strip("^"))
            fb.writelines(line)
    fb.close() 

我还包括了MANIFEST.inREADME.mdpackage.json(源)和requirements.txt以及上述文件。 执行:

pip install -e . -r requirements.txt

-e .用于本地安装,而-r requirements.txt用于安装上述库。当我执行它时,软件包已安装:

Obtaining file:///C:/Users/ha/json123
Installing collected packages: json123
Running setup.py develop for json123
Successfully installed json123

它没有按要求安装。

0 个答案:

没有答案