如何更改由`python setup.py bdist`创建的存档内的包路径?

问题描述

我正在通过命令 .zip 创建一个 python setup.py bdist 包。
创建存档后,我打包的主文件夹放在路径<archive_name>.zip/<Python_path>/Lib/site-packages/<packaged_folder>

我想要实现的是存档内的文件夹路径以保持一些特定,因为当我在不同环境中为相同的代码运行 python setup.py bdist 语句时,存档内的路径会根据 Python 版本和平台进行更改。

编辑:我不是在谈论 --dist-dir 选项。

解决方法

为此,您需要使用一些选项显式调用 installbdist_dumb 命令:
(是的,这是一个real command

setup.py install --root=build\bdist --install-lib=. bdist_dumb --bdist-dir=build\bdist

对于 install 命令,您需要覆盖以下选项:

--install-lib                        installation directory for all module distributions
--install-headers                    installation directory for C/C++ headers
--install-scripts                    installation directory for Python scripts
--install-data                       installation directory for data files

请注意,bdist 命令已过时,您想要的基本上就是 wheel format 的用途:

轮子是 ZIP 格式的存档,具有特殊格式的文件名和 .whl 扩展名。它包含一个发行版,几乎就像根据 PEP 376 使用特定安装方案安装一样。尽管建议使用专门的安装程序,但可以通过使用标准 unzip 工具简单地解压到站点包中来安装轮文件,同时保留足够的信息以便以后将其内容传播到最终路径上。

有关打包 Python 项目的最新信息,请参阅以下链接: