gpt4 book ai didi

python - 部署应用程序时无法从实例文件夹加载配置文件

转载 作者:太空狗 更新时间:2023-10-30 00:49:17 26 4
gpt4 key购买 nike

我为我的应用程序设置了一个新的 virtualenv,以清理已安装的包。我在应用程序的实例文件夹中有一个 config.py 文件。有两种配置,一种用于“实例”文件夹中的开发,一种用于根文件夹中的生产。该应用程序在旧的环境中工作,但现在我收到一个错误,它找不到配置文件。为什么会出现此错误以及如何解决?

Traceback (most recent call last):
File "application.py", line 12, in <module>
application.config.from_pyfile('config.py')
File "/Users/pavsidhu/Envs/test/lib/python2.7/site-packages/flask/config.py", line 128, in from_pyfile
with open(filename) as config_file:
IOError: [Errno 2] Unable to load configuration file (No such file or directory): '/Users/pavsidhu/Envs/test/var/application-instance/config.py'

我的项目结构如下:

/Users/pavsidhu/Envs/test/
lib/python-3.4/site-packages/
bin/
application.py
static/
templates/
instance/
config.py

最佳答案

Flask 认为您的应用程序安装在环境中,因为您将它放在与环境相同的基本目录中。详细描述了此行为 in the docs .

Installed module or package:

$PREFIX/lib/python2.X/site-packages/myapp
$PREFIX/var/myapp-instance

$PREFIX is the prefix of your Python installation.

以这种方式安装时,Flask 期望实例文件夹位于 var/myapp-instance。 (结构不完全相同,但足够相似以欺骗 Flask 的 detection function。)

你不应该把你的项目结构和 virtualenv 结构混在一起。将两者分开:

my_env/
lib/
bin/
my_project/
my_app/
__init__.py
static/
templates/
instance/

See the comment discussion moved to chat for further details.

关于python - 部署应用程序时无法从实例文件夹加载配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31164127/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com