Skip to content

fix: load_dotenv searches CWD when launched via console script#753

Open
AyushKar2005 wants to merge 1 commit intoTauricResearch:mainfrom
AyushKar2005:fix/cli-load-dotenv-cwd
Open

fix: load_dotenv searches CWD when launched via console script#753
AyushKar2005 wants to merge 1 commit intoTauricResearch:mainfrom
AyushKar2005:fix/cli-load-dotenv-cwd

Conversation

@AyushKar2005
Copy link
Copy Markdown

Problem

Fixes #726

so basically when you install tradingagents as a package and run it
via the console script (just typing tradingagents in terminal), the
.env file never gets picked up. all your API keys just dont load and
it feels like the .env doesnt exist at all.

Why this happens

turns out load_dotenv() by default looks for .env relative to
where the script is, not where you are in the terminal. when you run
python cli/main.py directly from the project folder it works fine
because the script is right there. but once its installed as a package
the script lives somewhere deep in site-packages so it never finds
your .env

Fix

changed load_dotenv() to load_dotenv(find_dotenv(usecwd=True)) in
both files. the usecwd=True part makes it search from whatever
directory the user is actually standing in when they run the command,
which is what you'd expect it to do in the first place honestly.

Files changed

  • cli/main.py — fixed both load_dotenv calls (the normal one and the .env.enterprise one)
  • main.py — fixed the load_dotenv call there too

load_dotenv() defaults to the script's directory, which breaks .env
loading when tradingagents is installed as a package and run from
a different directory via the console script entry point.

Fix by using find_dotenv(usecwd=True) so dotenv always searches
from the user's current working directory upward.

Fixes TauricResearch#726
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates environment variable loading across the project by utilizing find_dotenv(usecwd=True) in cli/main.py and main.py. Additionally, it modifies the default LLM configuration in main.py to use OpenRouter and specific Llama models while removing explanatory comments. The reviewer recommends reverting these configuration changes to maintain the PR's focus on the environment loading fix and to keep the example script accessible to users without specific external API keys.

Comment thread main.py
Comment on lines +8 to 18
config["llm_provider"] = "openrouter"
config["deep_think_llm"] = "meta-llama/llama-3.3-70b-instruct:free"
config["quick_think_llm"] = "meta-llama/llama-3.3-70b-instruct:free"
config["max_debate_rounds"] = 1

# Configure data vendors (default uses yfinance, no extra API keys needed)
config["data_vendors"] = {
"core_stock_apis": "yfinance", # Options: alpha_vantage, yfinance
"technical_indicators": "yfinance", # Options: alpha_vantage, yfinance
"fundamental_data": "yfinance", # Options: alpha_vantage, yfinance
"news_data": "yfinance", # Options: alpha_vantage, yfinance
"core_stock_apis": "yfinance",
"technical_indicators": "yfinance",
"fundamental_data": "yfinance",
"news_data": "yfinance",
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The changes to the LLM provider, model selection, and the removal of descriptive comments appear to be unrelated to the primary goal of fixing .env loading. Switching the default provider to openrouter and using a specific Llama model introduces a dependency on a non-default configuration and external API keys that may not be available to all users. It is recommended to revert these configuration changes to maintain the example script's accessibility and keep the PR focused on the bug fix.

Suggested change
config["llm_provider"] = "openrouter"
config["deep_think_llm"] = "meta-llama/llama-3.3-70b-instruct:free"
config["quick_think_llm"] = "meta-llama/llama-3.3-70b-instruct:free"
config["max_debate_rounds"] = 1
# Configure data vendors (default uses yfinance, no extra API keys needed)
config["data_vendors"] = {
"core_stock_apis": "yfinance", # Options: alpha_vantage, yfinance
"technical_indicators": "yfinance", # Options: alpha_vantage, yfinance
"fundamental_data": "yfinance", # Options: alpha_vantage, yfinance
"news_data": "yfinance", # Options: alpha_vantage, yfinance
"core_stock_apis": "yfinance",
"technical_indicators": "yfinance",
"fundamental_data": "yfinance",
"news_data": "yfinance",
}
config["deep_think_llm"] = "gpt-5.4-mini" # Use a different model
config["quick_think_llm"] = "gpt-5.4-mini" # Use a different model
config["max_debate_rounds"] = 1 # Increase debate rounds
# Configure data vendors (default uses yfinance, no extra API keys needed)
config["data_vendors"] = {
"core_stock_apis": "yfinance", # Options: alpha_vantage, yfinance
"technical_indicators": "yfinance", # Options: alpha_vantage, yfinance
"fundamental_data": "yfinance", # Options: alpha_vantage, yfinance
"news_data": "yfinance", # Options: alpha_vantage, yfinance
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli: load_dotenv() doesn't find user's .env when launched via the installed tradingagents console script

2 participants