我想实现与 Dask 库类似的行为,可以使用
pip
来安装 dask
、dask[dataframe]
、dask[array]
等。他们通过使用 setup.py
和软件包密钥像这样 来完成此操作。如果我只安装 dask
,则不会安装 dask[dataframe]
,并且在执行模块时它们会警告您。
我在诗歌文档中找到了this,但是当我执行
poetry build
时,我只得到一个.whl
文件,其中包含所有包。
如何打包我的模块以便能够使用
poetry
安装库的特定部分?
实际上,Dask 示例并不单独安装子包,它只是单独安装自定义依赖项,如此链接中所述。
为了使用诗歌完成相同的行为,您需要使用this(如用户@sinoroc在this评论中提到的)
诗歌附加页面的示例
pyproject.toml
是这样的:
[tool.poetry]
name = "awesome"
[tool.poetry.dependencies]
# These packages are mandatory and form the core of this package’s distribution.
mandatory = "^1.0"
# A list of all of the optional dependencies, some of which are included in the
# below `extras`. They can be opted into by apps.
psycopg2 = { version = "^2.7", optional = true }
mysqlclient = { version = "^1.3", optional = true }
[tool.poetry.extras]
mysql = ["mysqlclient"]
pgsql = ["psycopg2"]
通过使用
poetry build --format wheel
将创建单个轮子文件。
为了使用 pip 和wheel 文件安装一组特定的额外依赖项,您应该使用:
pip install "wheel_filename.whl[mysql]"