Python将自定义模块打包成whl并使用

打包需要的文件
__init__.py         :用于说明这个文件夹是一个python 的package包(可以为空文件)
cal_similarity.py :这个是要打包的测试文件
LICENSE           :这个是要打包支持的开源协议(可以为空文件)
setup.py             :这个脚本文件使用setuptools对自己的文件进行打包
READMED.md   :这个是对项目的一些使用方法的一些说明文件(可以为空文件)
README.md 对项目的一些使用方法的一些说明文件
LICENSE 打包支持的开源协议
Copyright (c) 2018 The Python Packaging Authority

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
pyproject.toml文件来描述项目信息
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "MuzhanTest"
version = "0.0.1"
authors = [
  { name="Example Author", email="author@example.com" },
]
description = "A small example package"
readme = "README.md"
requires-python = ">=3.7"
classifiers = [
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent",
]

[project.urls]
"Homepage" = "https://github.com/pypa/sampleproject"
"Bug Tracker" = "https://github.com/pypa/sampleproject/issues"

安装build
PS E:\coding\setting_egg> pip install --upgrade build
WARNING: Ignoring invalid distribution -pencv-python (e:\python3.10\lib\site-packages)
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: build in e:\python3.10\lib\site-packages (1.2.1)
Requirement already satisfied: packaging>=19.1 in e:\python3.10\lib\site-packages (from build) (23.2)
Requirement already satisfied: pyproject_hooks in e:\python3.10\lib\site-packages (from build) (1.0.0)
Requirement already satisfied: colorama in e:\python3.10\lib\site-packages (from build) (0.4.6)
Requirement already satisfied: tomli>=1.1.0 in e:\python3.10\lib\site-packages (from build) (2.0.1)
WARNING: Ignoring invalid distribution -pencv-python (e:\python3.10\lib\site-packages)

[notice] A new release of pip is available: 23.3 -> 24.1.2
[notice] To update, run: python.exe -m pip install --upgrade pip
  • 将模块进行编译,编译之后会出现dist文件夹
PS E:\coding\setting_egg> python -m build
* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
  - setuptools >= 40.8.0
* Getting build dependencies for sdist...
C:\Users\lenovo\AppData\Local\Temp\build-env-gj2jvs8n\lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:72: _MissingDynamic: `dependencies` defined outside of `pyproject.toml` is ignored.
********************************************************************************
The following seems to be defined outside of `pyproject.toml`:

`dependencies = ['requests', 'numpy']`

According to the spec (see the link below), however, setuptools CANNOT
consider this value unless `dependencies` is listed as `dynamic`.

https://packaging.python.org/en/latest/specifications/pyproject-toml/#declaring-project-metadata-the-project-table

To prevent this problem, you can list `dependencies` under `dynamic` or alternatively
remove the `[project]` table from your file and rely entirely on other means of
configuration.
********************************************************************************
!!
  _handle_missing_dynamic(dist, project_table)
C:\Users\lenovo\AppData\Local\Temp\build-env-gj2jvs8n\lib\site-packages\setuptools\config\expand.py:129: SetuptoolsWarning: File 'E:\\coding\\setting_egg\\README.md' cannot be found
  return '\n'.join(
C:\Users\lenovo\AppData\Local\Temp\build-env-gj2jvs8n\lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:79: SetuptoolsWarning: `install_requires` overwritten in `pyproject.toml` (dependencies)
  corresp(dist, value, root_dir)
running egg_info
creating wenxin.egg-info
writing wenxin.egg-info\PKG-INFO
writing dependency_links to wenxin.egg-info\dependency_links.txt
writing top-level names to wenxin.egg-info\top_level.txt
writing manifest file 'wenxin.egg-info\SOURCES.txt'
reading manifest file 'wenxin.egg-info\SOURCES.txt'
adding license file 'LICENSE'
writing manifest file 'wenxin.egg-info\SOURCES.txt'
* Building sdist...
C:\Users\lenovo\AppData\Local\Temp\build-env-gj2jvs8n\lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:72: _MissingDynamic: `dependencies` defined outside of `pyproject.toml` is ignored.
!!

        ********************************************************************************
        The following seems to be defined outside of `pyproject.toml`:

        `dependencies = ['requests', 'numpy']`

        According to the spec (see the link below), however, setuptools CANNOT
        consider this value unless `dependencies` is listed as `dynamic`.

        https://packaging.python.org/en/latest/specifications/pyproject-toml/#declaring-project-metadata-the-project-table

        To prevent this problem, you can list `dependencies` under `dynamic` or alternatively
        remove the `[project]` table from your file and rely entirely on other means of
        configuration.
        ********************************************************************************

!!
  _handle_missing_dynamic(dist, project_table)
C:\Users\lenovo\AppData\Local\Temp\build-env-gj2jvs8n\lib\site-packages\setuptools\config\expand.py:129: SetuptoolsWarning: File 'E:\\coding\\setting_egg\\README.md' cannot be found
  return '\n'.join(
C:\Users\lenovo\AppData\Local\Temp\build-env-gj2jvs8n\lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:79: SetuptoolsWarning: `install_requires` overwritten in `pyproject.toml` (dependencies)
  corresp(dist, value, root_dir)
running sdist
running egg_info
writing wenxin.egg-info\PKG-INFO
writing dependency_links to wenxin.egg-info\dependency_links.txt
writing top-level names to wenxin.egg-info\top_level.txt
reading manifest file 'wenxin.egg-info\SOURCES.txt'
adding license file 'LICENSE'
writing manifest file 'wenxin.egg-info\SOURCES.txt'
warning: sdist: standard file not found: should have one of README, README.rst, README.txt, README.md

running check
creating wenxin-0.0.1
creating wenxin-0.0.1\wenxin.egg-info
copying files to wenxin-0.0.1...
copying LICENSE -> wenxin-0.0.1
copying pyproject.toml -> wenxin-0.0.1
copying setup.py -> wenxin-0.0.1
copying wenxin.egg-info\PKG-INFO -> wenxin-0.0.1\wenxin.egg-info
copying wenxin.egg-info\SOURCES.txt -> wenxin-0.0.1\wenxin.egg-info
copying wenxin.egg-info\dependency_links.txt -> wenxin-0.0.1\wenxin.egg-info
copying wenxin.egg-info\top_level.txt -> wenxin-0.0.1\wenxin.egg-info
copying wenxin.egg-info\SOURCES.txt -> wenxin-0.0.1\wenxin.egg-info
Writing wenxin-0.0.1\setup.cfg
Creating tar archive
removing 'wenxin-0.0.1' (and everything under it)
* Building wheel from sdist
* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
  - setuptools >= 40.8.0
* Getting build dependencies for wheel...
C:\Users\lenovo\AppData\Local\Temp\build-env-lysc93n_\lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:72: _MissingDynamic: `dependencies` defined outside of `pyproject.toml` is ignored.
!!

        ********************************************************************************
        The following seems to be defined outside of `pyproject.toml`:

        `dependencies = ['requests', 'numpy']`

        According to the spec (see the link below), however, setuptools CANNOT
        consider this value unless `dependencies` is listed as `dynamic`.

        https://packaging.python.org/en/latest/specifications/pyproject-toml/#declaring-project-metadata-the-project-table

        To prevent this problem, you can list `dependencies` under `dynamic` or alternatively
        remove the `[project]` table from your file and rely entirely on other means of
        configuration.
        ********************************************************************************

!!
  _handle_missing_dynamic(dist, project_table)
C:\Users\lenovo\AppData\Local\Temp\build-env-lysc93n_\lib\site-packages\setuptools\config\expand.py:129: SetuptoolsWarning: File 'C:\\Users\\lenovo\\AppData\\Local\\Temp\\build-via-sdist-098ajdf8\\wenxin-0.0.1\\README.md' cannot be found 
  return '\n'.join(
C:\Users\lenovo\AppData\Local\Temp\build-env-lysc93n_\lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:79: SetuptoolsWarning: `install_requires` overwritten in `pyproject.toml` (dependencies)
  corresp(dist, value, root_dir)
running egg_info
writing wenxin.egg-info\PKG-INFO
writing dependency_links to wenxin.egg-info\dependency_links.txt
writing top-level names to wenxin.egg-info\top_level.txt
reading manifest file 'wenxin.egg-info\SOURCES.txt'
adding license file 'LICENSE'
writing manifest file 'wenxin.egg-info\SOURCES.txt'
* Building wheel...
C:\Users\lenovo\AppData\Local\Temp\build-env-lysc93n_\lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:72: _MissingDynamic: `dependencies` defined outside of `pyproject.toml` is ignored.
!!

        ********************************************************************************
        The following seems to be defined outside of `pyproject.toml`:

        `dependencies = ['requests', 'numpy']`

        According to the spec (see the link below), however, setuptools CANNOT
        consider this value unless `dependencies` is listed as `dynamic`.

        https://packaging.python.org/en/latest/specifications/pyproject-toml/#declaring-project-metadata-the-project-table

        To prevent this problem, you can list `dependencies` under `dynamic` or alternatively
        remove the `[project]` table from your file and rely entirely on other means of
        configuration.
        ********************************************************************************

!!
  _handle_missing_dynamic(dist, project_table)
C:\Users\lenovo\AppData\Local\Temp\build-env-lysc93n_\lib\site-packages\setuptools\config\expand.py:129: SetuptoolsWarning: File 'C:\\Users\\lenovo\\AppData\\Local\\Temp\\build-via-sdist-098ajdf8\\wenxin-0.0.1\\README.md' cannot be found 
  return '\n'.join(
C:\Users\lenovo\AppData\Local\Temp\build-env-lysc93n_\lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:79: SetuptoolsWarning: `install_requires` overwritten in `pyproject.toml` (dependencies)
  corresp(dist, value, root_dir)
running bdist_wheel
running build
installing to build\bdist.win-amd64\wheel
running install
running install_egg_info
running egg_info
writing wenxin.egg-info\PKG-INFO
writing dependency_links to wenxin.egg-info\dependency_links.txt
writing top-level names to wenxin.egg-info\top_level.txt
reading manifest file 'wenxin.egg-info\SOURCES.txt'
adding license file 'LICENSE'
Copying wenxin.egg-info to build\bdist.win-amd64\wheel\.\wenxin-0.0.1-py3.10.egg-info
running install_scripts
creating build\bdist.win-amd64\wheel\wenxin-0.0.1.dist-info\WHEEL
creating 'E:\coding\setting_egg\dist\.tmp-qchcdx78\wenxin-0.0.1-py3-none-any.whl' and adding 'build\bdist.win-amd64\wheel' to it
adding 'wenxin-0.0.1.dist-info/LICENSE'
adding 'wenxin-0.0.1.dist-info/METADATA'
adding 'wenxin-0.0.1.dist-info/WHEEL'
adding 'wenxin-0.0.1.dist-info/top_level.txt'
adding 'wenxin-0.0.1.dist-info/RECORD'
Successfully built wenxin-0.0.1.tar.gz and wenxin-0.0.1-py3-none-any.whl
PS E:\coding\setting_egg> cd dist
WARNING: Ignoring invalid distribution -pencv-python (e:\python3.10\lib\site-packages)
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing e:\coding\setting_egg\dist\wenxin-0.0.1-py3-none-any.whl
Successfully installed wenxin-0.0.1

显示成功安装自定义模块到环境中。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Cachel wood

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值