Jupyter Notebook 切换虚拟环境

方法

切换到需要添加到Jupyter Notebook中的虚拟环境,执行:

复制代码
python -m ipykernel install --name Jupyter Notebook中显示的虚拟环境名称

如果遇到
[Errno 13] Permission denied: '/usr/local/share/jupyter'类似的权限问题,可能是没有对应的路径,但是程序没有权限在该目录创建文件夹,因此需要对该路径赋予权限:

  1. 之前的权限

  2. 使用命令

    复制代码
    sudo chmod -R 777 /usr/local/share/jupyter
    sudo chmod +s /usr/local/share/jupyter
  3. 之后

解释:

  1. chmod -R 777 /usr/local/share/jupyter

    • -R:递归地更改目录及其子目录的权限。
    • 777:为所有用户赋予读、写、执行权限。
  2. chmod +s /usr/local/share/jupyter

    • +s:设置粘滞位,确保新创建的子目录继承父目录的权限。

注意事项:

  • 安全性

    赋予777权限意味着所有用户都可以读、写、执行该目录及其子目录,这可能引发安全问题。请确认这是完全必要的。如果仅需要特定用户组有权限,可以使用更精确的权限设置。

  • 建议

    若仅需某一组用户有此权限,可以考虑创建用户组并分配权限:

    bash 复制代码
    sudo groupadd jupyter_users
    sudo chown -R :jupyter_users /usr/local/share/jupyter
    sudo chmod -R 770 /usr/local/share/jupyter

参考

  1. Jupyter Notebook 切换虚拟环境(保姆级教程)_jupyter notebook切换虚拟环境-CSDN博客
  2. Jupyter中kernel的添加与删除_如何删除jupyter中的虚拟环境-CSDN博客
  3. 02- Anaconda查看、创建、切换虚拟环境 & Jupyter notebook切换Python环境 & Jupyter中kernel的添加与删除 - TR_Goldfish - 博客园 (cnblogs.com)
相关推荐
曲幽9 小时前
数据库实战:FastAPI + SQLAlchemy 2.0 + Alembic 从零搭建,踩坑实录
python·fastapi·web·sqlalchemy·db·asyncio·alembic
用户83562907805114 小时前
Python 实现 PowerPoint 形状动画设置
后端·python
ponponon15 小时前
时代的眼泪,nameko 和 eventlet 停止维护后的项目自救,升级和替代之路
python
Flittly15 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(5)Skills (技能加载)
python·agent
敏编程15 小时前
一天一个Python库:pyarrow - 大规模数据处理的利器
python
Flittly17 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(4)Subagents (子智能体)
python·agent
明月_清风1 天前
Python 装饰器前传:如果不懂“闭包”,你只是在复刻代码
后端·python
明月_清风1 天前
打破“死亡环联”:深挖 Python 分代回收与垃圾回收(GC)机制
后端·python
ZhengEnCi2 天前
08c. 检索算法与策略-混合检索
后端·python·算法
明月_清风2 天前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python