mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-08 03:37:24 -04:00
fix: set PYTHONPATH for MCP services to resolve import errors
Root cause: Python adds script directory (not working directory) to sys.path. Services in /app/agent_tools/ couldn't import from /app/tools/ because sys.path[0] was /app/agent_tools. Solution: Set PYTHONPATH=/app when starting services so /app is always in the Python import path. Fixes: ModuleNotFoundError: No module named 'tools' in price.log
This commit is contained in:
@@ -79,12 +79,18 @@ class MCPServiceManager:
|
|||||||
try:
|
try:
|
||||||
# Start service process
|
# Start service process
|
||||||
log_file = self.log_dir / f"{service_id}.log"
|
log_file = self.log_dir / f"{service_id}.log"
|
||||||
|
|
||||||
|
# Set PYTHONPATH to /app so services can import from tools module
|
||||||
|
env = os.environ.copy()
|
||||||
|
env['PYTHONPATH'] = str(Path.cwd())
|
||||||
|
|
||||||
with open(log_file, 'w') as f:
|
with open(log_file, 'w') as f:
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
[sys.executable, str(script_path)],
|
[sys.executable, str(script_path)],
|
||||||
stdout=f,
|
stdout=f,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
cwd=Path.cwd() # Use current working directory (/app)
|
cwd=Path.cwd(), # Use current working directory (/app)
|
||||||
|
env=env # Pass environment with PYTHONPATH
|
||||||
)
|
)
|
||||||
|
|
||||||
self.services[service_id] = {
|
self.services[service_id] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user