我正试图使用setuptools建立一个项目。在我的项目中,出现了必不可少的 config.yaml
文件。我已经指定了这样的。
setup=(
# some stuff
include_package_data=True,
package_data={
"": ["*.yaml"]
},
# some remains stuff
)
但我得到的问题是 config.yaml
没有找到。当我启动一个应用程序时,就会出现这种情况。
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\github\\Cats_Queue_Management_System\\env\\lib\\site-packages\\kitty_getter-1.0-py3.8.egg\\application\\config.yaml'
然而,它已经被复制了。(根据我的理解)。
copying build\lib\application\config.yaml -> build\bdist.win32\egg\application
python代码中的文件交互。
# some stuff
default_file = Path(__file__).parent.parent / 'config.yaml'
with open(default_file, 'r') as f:
config = yaml.safe_load(f)
# some remains stuff
项目的安排如下。
Project/
+- app/
| +- __init__.py
| +- src/
| | +- __init__.py
| | +- config_processing.py
| +- entry_point.py
| +- config.yaml
+- setup.py
或者更完整的版本(文件交互发生在... settings.py
):
另外,我想说的是,如果我直接启动应用程序,我的意思是... python entry_point.py
它的工作原理。
因为这个文件在那里不存在... ... 你的.yaml文件在 D:/github/Cats_Queue_Management_System/application/config.yaml 你试着在错误的路径上搜索它。
试试这个就知道了。
import os
fileName = "config.yaml"
appPath = r"D:\github"
for r,d,f in os.walk(appPath):
for file in f:
if file == fileName:
print(os.path.abspath(file))
else:
print(f"File {fileName} is not exist!")
这将在所有appPath文件夹和子文件夹中搜索你的文件 如果找到了将打印出文件的绝对路径 如果没有将告诉你文件不存在.