python setup.py 打包非py文件,并安装到python 库中
使用python setup.py打包py库,同时需要包含非py文件
示例项目:将mylib/doc 目录下的文件打包,并可以正常安装到site-packages 目录下
解决方案:
- 在MAINDEST.in 文件中加入:“recursive-include mylib/doc *.html“ , 并且在setup.py 中设置: install_package_data=True。
注意:如果在MANIFEST.in 文件中加了: “recursive-include mylib/doc *.html“, 但没有设置 install_pakcage_data=True, 则只会将doc下面的文件打包到dist/mylib.*.tar.gz 中, 但是安装时并不会将doc 目录的文件一并安装到 site-packages 目录下。
- 项目目录:
- setup.py
from setuptools import setup, find_packages
setup(
name="mylib",
version="0.0.2",
author="your name",
author_email="xxx.163.com",
description="",
long_description="my libary",
long_description_content_type="text/markdown",
packages=find_packages(where='.', exclude=(), include=('*',)),
include_package_data=True,
install_requires=[
"urllib3>=1.25.11",
],
classifiers=[
"Programming Language :: Python :: 3",
"License :: Free for non-commercial use",
"Operating System :: OS Independent",
]
)
- MANIFEST.in
recursive-include mylib/doc *.html
测试命令:
python setup.py sdist
@REM twine upload -u sfpypi-common -p sfpypi --repository-url http://your.registry.org/sfpypi/ dist/mylib*.tar.gz
@REM python build_doc.py
pip uninstall mylib
pip install dist\mylib-0.0.2.tar.gz