资源在本地可用,但“没有这样的文件或目录”与 Poetry 一起打包和部署时
我使用定义为常量的路径,例如 TF_CONSTS = 'consts/tf_keras_param_config.json' ,它们在开发过程中工作正常。
但是,当使用 Poetry 构建包(即 poetry build --format sdist)并部署时,即使 JSON 文件与 Python 脚本一起复制,这些引用也会变得无效:
FileNotFoundError: [Errno 2] No such file or directory: 'some_package/consts/tf_keras_param_config.json'
为什么?
I use paths defined as constants, e.g. TF_CONSTS = 'consts/tf_keras_param_config.json'
and they work fine during development.
However, when the package is built with Poetry (i.e. poetry build --format sdist
) and deployed, these references become invalid even though the JSON files are copied along with the Python scripts:
FileNotFoundError: [Errno 2] No such file or directory: 'some_package/consts/tf_keras_param_config.json'
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
相对路径在开发过程中工作正常,但是 - 当代码打包然后安装时 - 它们必须转换为绝对路径,并且必须动态确定这些路径(它们取决于已安装包的位置):
另请考虑 importlib.resources:
Relative paths work fine during development, but - when the code is packaged and then installed - they must be translated to absolute ones and these must be determined dynamically (they depend on the location of the installed package):
Consider also importlib.resources: