如何编写一个设置。Py确保非编码(数据)文件与我的脚本相同的相对路径与我的存储库相同?
当我开发一个项目时,脚本script.py
需要访问某些数据文件data.txt
,我通常会写下类似的内容:
path = Path(__file__).parent.parent / "resources" / "text" / "data.txt"
然后我提交<代码> data.txt 来源控制,当人们克隆回购时,一切都会起作用。这效果很好,直到项目成熟到我想编写setup.py
的地步,让人们只用pip直接将其安装。在这一点存储库。我已经研究了package_data
,data_files
和subtest.in
,但我无法获得任何解决方案。我该怎么做?
When I'm developing a project, and a script script.py
needs access to some data file data.txt
, I will usually write something like this:
path = Path(__file__).parent.parent / "resources" / "text" / "data.txt"
I then commit data.txt
to source control, and when people clone the repo, everything will work. This works nicely until the project matures to the point that I want to write a setup.py
to let people just install it straight from the repo with pip. At this point, I can't figure out how to tell setup.py
to just put the resources
folder in the "same place" in the package as it is in my repository. I've looked into package_data
, data_files
and MANIFEST.in
but I haven't been able to get any solution working. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论