question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cant find settings when running the program from another folder than root folder

See original GitHub issue

Hi, 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:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jgiudicicommented, Jul 18, 2018

Maybe the search for the settings file must begging on the dir of the called script and not pwd?

1reaction
brucegibbinscommented, Sep 10, 2018

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:

I want o implement those changes without breaking backwards compatibility with existing use cases.

For that I need to figure out 2 things:

How to get the path the script has been called (instead its pwd) including the django and flask cases. 2.

to have a default folder name, I would call it by default ‘dynaconf/’ , ‘conf/’ or ‘settings/’ I would default to a folder called settings but not sure if it can break existing projects already using that folder name.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rochacbruno/dynaconf/issues/74#issuecomment-419909389, or mute the thread https://github.com/notifications/unsubscribe-auth/AQF3GM76rflXJhDac7rQl2Tu7Wqa95Yqks5uZmc6gaJpZM4VUyjv .

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found