- 项目结构如图所示
rootfolder/
ellis/
__init__.py
func/
__init__.py
main.py
setup.py
其中main.py如下
def test(value):
print(value)
ellis/init.py如下
from func.main import test
def haha(value):
test(value)
setup.py 如下
from setuptools import setup, find_packages
setup(
#包名
name='ellis',
version='0.1',
#entry_points 可以让你在安装包时自动注册一些可执行命令或者插件,这样用户就可以直接使用这些命令或者插件,而不需要手动配置。
entry_points={
'console_scripts': [
'ellis=ellis:haha'
]
},
#以来的包
install_requires=[
'numpy==1.1',
'pandas'
],
author='Your Name',
author_email='your_email@example.com',
description='A simple Python package',
# long_description=open('README.md').read(),
long_description_content_type='text/markdown',
url='https://github.com/your_username/my_package',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
],
include_package_data=True,
package_dir={"": "."},
#将文件夹下所有文件打入安装包
packages=find_packages(where="."),
)
- 制作安装包
python setup.py sdist
- 安装
pip install ellis-0.1.tar.gz
此时就可以引用了
from ellis import haha
haha(123)
参考
https://write.agrevolution.in/packaging-a-django-project-using-setuptools-c1d7d565779e
https://docs.python.org/3/distutils/setupscript.html
https://stackoverflow.com/questions/1612733/including-non-python-files-with-setup-py
https://carpentries-incubator.github.io/python_packaging/instructor/03-building-and-installing.html