构建和引用可编辑的本地 Python 模块的正确方法是什么?

What is the proper way to build and reference an editable local Python module?

提问人:Josh Russo 提问时间:11/15/2023 最后编辑:Josh Russo 更新时间:11/15/2023 访问量:40

问:

我正在尝试构建一个模块,该模块将在项目中的多个 Python 应用程序之间共享。

我有一个文件夹,其中包含以下内容。pyproject.toml

[project]
name = "data_audit_shared"
version = "0.0.1"
authors = [
    { name="Josh Russo", email="[email protected]" },
]
description = "Shared code for data audit"
requires-python = ">=3.8"
classifiers = [
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent",
]

当我尝试引用时,我收到消息.data_audit_sharedNo module named 'data_audit_shared'

我在项目中的依赖项是,它可以正确安装。-e ../../data_audit_shared

这就是我的 venv 的样子。site-packages

enter image description here

如何更新模块或引用才能使用此模块?


编辑 - 尝试删除-e

因此,当我删除时,我会得到已安装模块中列出的模块。我是否缺少一些东西来正确安装和引用我的模块?-e-e


编辑 - 相对路径

我假设这是因为我试图引用项目文件夹根目录之外的包。在我看来,奇怪的部分是您可以将这种语法与 Git 存储库一起使用。为什么它的行为不类似?

python pip python-module pyproject.toml

评论

0赞 juanpa.arrivillaga 11/15/2023
它的行为不应该不同。我认为您需要向我们提供更多详细信息,包括您正在使用的精确命令,倾向于排除您出于某种原因安装到错误的虚拟环境。
0赞 Josh Russo 11/15/2023
@juanpa.arrivillaga 好吧,我只是试图创建一个例子,它奏效了。我需要回到我的另一个项目,看看我是否能确定我做错了什么。

答: 暂无答案