解决Did not find dashscope_api_key问题——jupyter设置环境变量

jupyter中使用通义千文+langchain 报错

bash 复制代码
Value error, Did not find dashscope_api_key, please add an environment variable `DASHSCOPE_API_KEY` which contains it, or pass `dashscope_api_key` as a named parameter.

我本来以为这样就是已经加上了:

python 复制代码
#导入相关包
import os
from dotenv import find_dotenv, load_dotenv
DASHSCOPE_API_KEY="sk-XXXXXXXX"
from langchain_community.llms import Tongyi
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate

其实不是。

需要在Jupyter Notebook的cell中,使用Python的os模块来设置环境变量。

设置好之后就可以调用了。

相关推荐
AlickLbc14 分钟前
在phpstudy环境下配置搭建XDEBUG配合PHPSTORM的调试环境
ide·phpstorm
悠悠小茉莉15 分钟前
Win11 安装 Visual Studio(保姆教程 - 更新至2025.07)
c++·ide·vscode·python·visualstudio·visual studio
m0_6256865530 分钟前
day53
python
Real_man1 小时前
告别 requirements.txt,拥抱 pyproject.toml和uv的现代Python工作流
python
站大爷IP2 小时前
Python文件操作的"保险箱":with语句深度实战指南
python
运器1232 小时前
【一起来学AI大模型】算法核心:数组/哈希表/树/排序/动态规划(LeetCode精练)
开发语言·人工智能·python·算法·ai·散列表·ai编程
yanjiee2 小时前
需要scl来指定编译器的clangd+cmake在vscode/cursor开发环境下的配置
ide·vscode·编辑器
巴里巴气4 小时前
selenium基础知识 和 模拟登录selenium版本
爬虫·python·selenium·爬虫模拟登录
19894 小时前
【零基础学AI】第26讲:循环神经网络(RNN)与LSTM - 文本生成
人工智能·python·rnn·神经网络·机器学习·tensorflow·lstm
JavaEdge在掘金4 小时前
Redis 数据倾斜?别慌!从成因到解决方案,一文帮你搞定
python