Cant find settings when running the program from another folder than root folder
See original GitHub issueHi, I have this folder structure:
test_dynaconf
└── subfolder
├── main.py
└── settings.toml
with main.py:
#main.py
from dynaconf import settings
print(settings["KEY1"])
and settings.toml:
#settings.toml
[default]
KEY1="hi"
If I run from subfolder, everything works:
➜ subfolder python3 main.py
hi
But if I run from test_dynaconf or another path, it breaks:
test_dynaconf python3 subfolder/main.py
Traceback (most recent call last):
File "subfolder/main.py", line 3, in <module>
print(settings["KEY1"])
File "/usr/local/lib/python3.5/dist-packages/dynaconf/utils/functional.py", line 208, in inner
return func(self._wrapped, *args)
File "/usr/local/lib/python3.5/dist-packages/dynaconf/base.py", line 193, in __getitem__
raise KeyError('{0} does not exists'.format(item))
KeyError: 'KEY1 does not exists'
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Cant find settings when running the program from another ...
Hi, I have this folder structure: test_dynaconf └── subfolder ├── main.py └── settings.toml with main.py: #main.py from dynaconf ...
Read more >Microsoft does not support changing the location of the ...
Steps to change the ProgramFilesDir registry value to use the default location for the Program Files folder · Click Start, click Run, type...
Read more >11 Ways to Fix "The System Cannot Find The Path Specified ...
In Windows Search, type "Command Prompt." · Press and hold Win + I keys to open Settings. · On your computer, open File...
Read more >Multi-root Workspaces in Visual Studio Code
You can open and work on multiple project folders in Visual Studio Code with multi-root workspaces.
Read more >Importing files from different folder - python - Stack Overflow
If you run it from your root folder (ie. application folder), you are probably fine with sys.path.append('.') then importing the module by using...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Maybe the search for the settings file must begging on the dir of the called script and not pwd?
Thank you for your reply. As I am old coder but new to the python environ please forgive my naive questions. Despite being aware of their purpose I am unfamiliar with the workings of Flask or Django so cannot offer any suggestions. However, would it not be possible to leave everything as you currently have it but allow the calling module to set PROJECT_ROOT_FOR_DYNACONF to use a relative path based on the module that first instantiated settings? I may be missing a number of pythonic things here and over simplifying it. But for us we would just like to be able to override the default reading of settings.yml to use conf/settings.yml instead. Our environment is a pure CLI so Flask and Django are not in our focus at this stage. cheers
On Mon, Sep 10, 2018 at 11:21 PM Bruno Rocha notifications@github.com wrote: