Skip to content

How to disable python-dotenv #510

Closed
Closed

Description

@matthewfranglen

Quite a lot of packages use this library. I have an .env file which I use for a different purpose and cannot be parsed by python-dotenv. I get a lot of messages like:

Python-dotenv could not parse statement starting at line 1
Python-dotenv could not parse statement starting at line 2

Is there an environmental variable that I can set that will disable python-dotenv?

I am not asking about a specific library as I've already encountered this error in flask, pipenv and nltk. Since this library deals with the environment already I think having an environmental variable to disable it is not unreasonable.

Activity

  1. duarte-pompeu commented on Jun 12, 2024

    @duarte-pompeu

    I'm not sure it will solve it, but I thought of a workaround: point to another file via the -f parameter:

    $ echo "a=1" > .env
    $ echo "b=2" > /tmp/dummy.env
    $ dotenv list # by default grabs vars from .env
    a=1
    $ dotenv -f /tmp/dummy.env list # does not grab them when pointing towards other file
    b=2
  2. matthewfranglen commented on Jun 17, 2024

    @matthewfranglen
    ContributorAuthor

    The problem is that I don't want dotenv, it is being loaded by a transitive dependency. I don't call the code and there is no way for me to choose the file that it loads.

    The dotenv cli doesn't help with that as the -f setting does not alter how the library loads in future. One solution to this issue would be an environmental variable that points to the file to use, and if set but blank then dotenv reads nothing.

  3. gaardhus commented on Sep 13, 2024

    @gaardhus

    I'm having same problem currently getting warnings since I have set up my .env in another way.

  4. gaardhus commented on Sep 13, 2024

    @gaardhus

    Adding the following suppressions to my import statements "solved" it.

    import logging
    import warnings
    
    logging.disable(logging.CRITICAL)
    
    with warnings.catch_warnings(action="ignore"):
        from litellm import completion
  5. theskumar commented on Jun 24, 2025

    @theskumar
    Owner

    I believe skipping just the autoloader for load_dotenv() with a environment variable is probably cleanest option here, unless someone else has a better idea!

    DOTENV_AUTOLOAD_DISABLED=1
    DOTENV_AUTOLOAD_DISABLED=true
    

    That said, the downstream library should provide a way to skip the call to load_dotenv(), apart from just detecting if python-dotenv is installed or not.

    Happy to review a PR!

  6. added a commit that references this issue on Jun 24, 2025
    c715d19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions