如果从其他文件运行脚本,Python 无法找到数据库

问题描述 投票:0回答:2

已在评论中解决

我在一个数据量大的项目中遇到了困难。我可以运行一个使用查询文件的文件——所有查询和转换器都在这里——没有问题,但是当我运行一个再次运行该文件的文件时,我收到一个错误,指出无法找到数据库。

so: 
Queryfile() : No problem,
Queryfile() -> Actionfile() : No problem,
Queryfile() -> Actionfile() -> action_manager(): Error, cant find db,
Queryfile() -> Actionfile() -> action_manager() -> startupfile(): Giant error, no way to solve it.

我的目标是在主目录中构建一个启动文件并从那里触发所有需要的脚本,但我不断收到此错误:

    (sqlite3.OperationalError) unable to open database file
(Background on this error at: https://sqlalche.me/e/14/e3q8)
('ERROR_LOADING_ANALYSES', OperationalError('(sqlite3.OperationalError) unable to open database file'))

这真的很糟糕,我不知道我需要什么才能让这个项目运行。如果有任何替代方法,例如将工作目录移至此文件,运行它并移回,我想知道。请让我知道你是如何处理这个问题的。

这是我的项目树。

├───core_data
│   ├───data_temp
│   ├───**DATABASE**
├───core_update
│   ├───update_main
│   │   └───__pycache__
│   ├───update_additional_scripts
│   │   └───__pycache__
├───core_utils
│   ├───database_querys
│   │   └───__pycache__
│   ├───database_tables
│   │   └───__pycache__
├───startup file 
├───constants. 

期待您的回复。

python sqlite data-science
2个回答
0
投票

解决方案是将项目工作目录移动到文件夹的开头以及系统路径的路径中。


0
投票

您可以通过使用 python.toml 文件(带有源文件“src”)构建包来解决此问题,然后使用 pip install -e 安装该包。在您的项目文件和完成的目录中。

© www.soinside.com 2019 - 2024. All rights reserved.