jupyter中切换Anaconda虚拟环境

jupyter中切换虚拟环境

  1. 查看python路径
python 复制代码
import sys
sys.executable

这个命令会输出当前 Notebook 使用的 Python 可执行文件的路径

  1. 查看安装的包和环境信息(前两步都在jupyter notebook中进行)
python 复制代码
!which python
!python --version
!pip list
  1. 将你的虚拟环境加入 Jupyter Notebook(回到Anaconda Powershell Prompt)
    假设你的环境叫 myenv
python 复制代码
conda activate myenv
  1. 在环境里装 Jupyter 和 ipykernel
python 复制代码
conda install ipykernel

或者

python 复制代码
pip install ipykernel
  1. 把环境注册到 Jupyter 中
python 复制代码
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
  1. 打开 Jupyter Notebook切换 Kernel
python 复制代码
jupyter notebook

如果你想删除一个已经注册的kernel:

python 复制代码
jupyter kernelspec uninstall myenv

查看anaconda中有哪些虚拟环境切换并且查看是否已经有ipykernel

  1. 查看anaconda中有哪些虚拟环境
python 复制代码
conda env list
  1. 激活虚拟环境
python 复制代码
conda activate your_env_name
  1. 查看虚拟环境中是否有ipykernel
python 复制代码
pip show ipykernel

如果有安装,你会看到类似输出:

python 复制代码
Name: ipykernel
Version: 6.29.2
...

如果没有任何输出,说明这个环境还没装 ipykernel

也可以用 pip list 看看安装了哪些包

python 复制代码
pip list

然后在结果中找 ipykernel

还可以使用:

python 复制代码
conda list ipykernel

如果有安装,你会看到:

python 复制代码
ipykernel                 6.29.2           py39haa95532_0

下载langchain

python 复制代码
pip install langchain

或者

python 复制代码
conda install langchain

国内还可以使用清华镜像源

python 复制代码
pip install langchain -i https://pypi.tuna.tsinghua.edu.cn/simple
相关推荐
ZZHow10241 天前
02OpenCV基本操作
python·opencv·计算机视觉
计算机学长felix1 天前
基于Django的“酒店推荐系统”设计与开发(源码+数据库+文档+PPT)
数据库·python·mysql·django·vue
站大爷IP1 天前
Python随机数函数全解析:5个核心工具的实战指南
python
悟乙己1 天前
使用 Python 中的强化学习最大化简单 RAG 性能
开发语言·python·agent·rag·n8n
max5006001 天前
图像处理:实现多图点重叠效果
开发语言·图像处理·人工智能·python·深度学习·音视频
AI原吾1 天前
玩转物联网只需十行代码,可它为何悄悄停止维护
python·物联网·hbmqtt
云动雨颤1 天前
Python单元测试入门:3个核心断言方法,帮你快速定位代码bug
python·单元测试
子兮曰1 天前
🔥C盘告急!WSL磁盘暴增?三招秒清20GB+空间
前端·windows·docker
SunnyDays10111 天前
Python 实现 HTML 转 Word 和 PDF
python·html转word·html转pdf·html转docx·html转doc
跟橙姐学代码1 天前
Python异常处理:告别程序崩溃,让代码更优雅!
前端·python·ipython