langflow-ai/langflow

langflow not respecting env file.

Closed this issue · 3 comments

jtoy commented

Bug Description

I start langflow like this:
python3 -m langflow run --env-file .langflow.env
it doesn't respect the env file.

Here is the env file I am using:
LANGFLOW_SUPERUSER=admin
LANGFLOW_SUPERUSER_PASSWORD=password
LANGFLOW_AUTO_LOGIN=false
LANGFLOW_HOST=0.0.0.0

Reproduction

  1. pip install langlow

Expected behavior

it should respect the .env file.

Who can help?

No response

Operating System

Ubuntu 20.04.4 LTS

Langflow Version

1.0.18

Python Version

3.10

Screenshot

No response

Flow File

No response

There are a couple of similar issues that might be relevant to your problem:

  1. Features change when langflow is run from the Env Variables - This issue was closed and the solution involved ensuring that the correct options were included in the configuration files.
  2. LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT not loading any environment variables - This issue was also closed, and the solution was to format the environment variables as a comma-separated list instead of a JSON-encoded string.

For your specific issue, ensure that the --env-file parameter is correctly passed in the command. The correct command should be:

python3 -m langflow run --env-file .langflow.env

Make sure that the .env file is correctly named and located in the same directory from which you are running the command. According to the Langflow documentation, the --env-file option specifies the path to the .env file containing environment variables, and the default is .env. The code snippet shows that the env_file parameter is used to load environment variables if provided:

if env_file:
    load_dotenv(env_file, override=True)

Additionally, other configuration files or settings in Langflow, such as config.yaml and command-line options, might override or conflict with the .env file settings [1][2][3].

To continue talking to Dosu, mention @dosu.

Hi there! How’s it going?
I followed the steps you described, and everything worked perfectly for me. I had to log in using 'admin' and 'password'. I also tried using a different password, and it worked as expected.
Could you be more specific about the error or behavior you're encountering?

I think I understand your issue.
If you try the following command, I believe you won't encounter any problems:

export $(xargs < .langflow.env) && langflow run --env-file .langflow.env

This happens because we have two configuration methods: one through the CLI using typer, and another via a configuration file using pydantic-settings.

The --env-file parameter in typer, which specifies an alternate file with environment variables, can't override its own settings like --host. Therefore, for it to work as expected, you would need to have already declared LANGFLOW_HOST in your environment.

It's definitely confusing and should be improved.