python源码包打包成.whl文件

主要命令

  1. 检查
$ python setup.py check
  1. 打包
    这里注意python版本,可能需要使用python3
$ python setup.py sdist bdist_wheel || true

打包过程

SudachiDict-core-20211220为例。

  1. 下载并解压.tar.gz文件
  2. 准备工作

进入根目录(根目录中有setup.py文件)
SudachiDict-core-20211220打包过程会下载字典,打开setup.py文件,注释或删除下面的行。因为该字典在外网,一般会因为下载速度慢而失败。

if not os.path.exists(RESOURCE_DIR):
    logger.warning("Downloading the Sudachi dictionary (It may take a while) ...")
    _, _msg = urlretrieve(ZIP_URL, ZIP_NAME)
    with ZipFile(ZIP_NAME) as z:
        z.extractall()

改为以下内容,因为下载很慢会一直失败,需要手动下载字典然后放入目录中。

if not os.path.exists(RESOURCE_DIR):
    logger.warning("Downloading the Sudachi dictionary (It may take a while) ...")
    # _, _msg = urlretrieve(ZIP_URL, ZIP_NAME)
    with ZipFile(ZIP_NAME) as z:
        z.extractall()
  1. 检查
$ python setup.py check
  1. 执行打包命令
$ python setup.py sdist bdist_wheel || true

至此会在根目录中的dist目录中生成.whl文件

来发评论吧~
Powered By Valine
v1.5.2