> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 变量缓存问题排查

如果您在追踪项目中看不到追踪记录，或发现追踪记录被错误地记录到其他项目/工作区，问题可能源于 LangSmith 默认的环境变量缓存机制。这在 Jupyter notebook 中运行 LangSmith 时尤为常见。请按照以下步骤诊断并解决问题：

## 1. 验证环境变量

首先，通过运行以下代码检查环境变量是否正确设置：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import os
print(os.getenv("LANGSMITH_PROJECT"))
print(os.getenv("LANGSMITH_TRACING"))
print(os.getenv("LANGSMITH_ENDPOINT"))
print(os.getenv("LANGSMITH_API_KEY"))
```

如果输出结果与您在 .env 文件中定义的内容不符，很可能是因为环境变量被缓存了。

## 2. 清除缓存

使用以下命令清除缓存的环境变量：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
utils.get_env_var.cache_clear()
```

## 3. 重新加载环境变量

通过执行以下代码从 .env 文件重新加载环境变量：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from dotenv import load_dotenv
import os
load_dotenv(<.env 文件路径>, override=True)
```

重新加载后，您的环境变量应该会被正确设置。

如果问题仍然存在，请通过共享的 Slack 频道或邮件支持（适用于 Plus 和 Enterprise 计划）联系我们，或在 [LangChain 论坛](https://forum.langchain.com/)中寻求帮助。

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\langsmith\troubleshooting-variable-caching.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
