我正在构建一个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.in
,README.md
,package.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
它没有按要求安装。