From db7e0a67e2722a5be8b870f5661efa3b6753419a Mon Sep 17 00:00:00 2001 From: Yijia-Xiao Date: Sun, 10 May 2026 09:49:07 +0000 Subject: [PATCH] fix(cli): load .env from user's CWD when run as console script load_dotenv() with no arguments walks up from site-packages instead of the user's CWD, so the installed tradingagents console script silently misses the project's .env. Pass find_dotenv(usecwd=True) so the search starts from CWD; same treatment for .env.enterprise. #726 #755 #612 #747 #743 #753 #729 #728 #751 --- cli/main.py | 10 ++++++---- main.py | 5 ++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cli/main.py b/cli/main.py index 534f50379..05376ade2 100644 --- a/cli/main.py +++ b/cli/main.py @@ -4,11 +4,13 @@ import typer from pathlib import Path from functools import wraps from rich.console import Console -from dotenv import load_dotenv +from dotenv import find_dotenv, load_dotenv -# Load environment variables -load_dotenv() -load_dotenv(".env.enterprise", override=False) +# Search starts from the user's CWD so the installed `tradingagents` +# console script picks up the project's .env instead of walking up from +# site-packages. +load_dotenv(find_dotenv(usecwd=True)) +load_dotenv(find_dotenv(".env.enterprise", usecwd=True), override=False) from rich.panel import Panel from rich.spinner import Spinner from rich.live import Live diff --git a/main.py b/main.py index c94fde323..fa3024af8 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,9 @@ from tradingagents.graph.trading_graph import TradingAgentsGraph from tradingagents.default_config import DEFAULT_CONFIG -from dotenv import load_dotenv +from dotenv import find_dotenv, load_dotenv -# Load environment variables from .env file -load_dotenv() +load_dotenv(find_dotenv(usecwd=True)) # Create a custom config config = DEFAULT_CONFIG.copy()