Conda 安装 Jupyter Notebook

文章目录

        • [1. 安装 Conda](#1. 安装 Conda)
        • [2. 创建虚拟环境](#2. 创建虚拟环境)
        • [3. 安装 Jupyter Notebook](#3. 安装 Jupyter Notebook)
        • [4. 启动 Jupyter Notebook](#4. 启动 Jupyter Notebook)
        • [5. 安装扩展功能(可选)](#5. 安装扩展功能(可选))
        • [6. 更新与维护](#6. 更新与维护)
        • [7. 总结](#7. 总结)

Jupyter Notebook 是一款非常流行的交互式开发工具,尤其适合数据科学、机器学习和教学场景。借助 Conda,我们可以方便地安装和管理 Jupyter Notebook 及其依赖。

1. 安装 Conda

在安装 Jupyter Notebook 之前,确保系统已安装 Conda。Conda 可以通过 Anaconda 或 Miniconda 提供。

  • Anaconda: 完整的 Python 数据科学平台,包含许多常用包。
  • Miniconda: 精简版,仅包含 Conda 和 Python,适合自定义环境。
下载与安装步骤:
  1. 访问 Miniconda 下载页面Anaconda 下载页面

  2. 下载适合您操作系统的安装包。

  3. 执行安装脚本:

    bash 复制代码
    # 示例:在 Linux 系统上安装 Miniconda
    bash Miniconda3-latest-Linux-x86_64.sh
  4. 按提示完成安装。

安装完成后,运行以下命令验证 Conda 是否安装成功:

bash 复制代码
conda --version
2. 创建虚拟环境

使用 Conda 创建独立的 Python 环境,可以避免不同项目间的依赖冲突。

bash 复制代码
conda create -n jupyter_env python=3.9 -y

激活环境:

bash 复制代码
conda activate jupyter_env
3. 安装 Jupyter Notebook

在激活的虚拟环境中,运行以下命令安装 Jupyter Notebook:

bash 复制代码
conda install -c conda-forge notebook -y

安装完成后,验证安装:

bash 复制代码
jupyter notebook --version
4. 启动 Jupyter Notebook

启动 Notebook 服务:

bash 复制代码
jupyter notebook

成功启动后,您将在终端看到类似以下的输出:

复制代码
http://localhost:8888/tree

复制链接到浏览器,即可访问 Jupyter Notebook 界面。

注意:这只允许本地访问

如果实现远程访问

bash 复制代码
jupyter notebook --allow-root --ip=0.0.0.0 --port=8888

输出:

bash 复制代码
[I 2025-01-03 15:08:19.708 ServerApp] notebook | extension was successfully linked.
[I 2025-01-03 15:08:19.799 ServerApp] notebook_shim | extension was successfully linked.
[I 2025-01-03 15:08:19.805 ServerApp] notebook_shim | extension was successfully loaded.
[I 2025-01-03 15:08:19.806 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2025-01-03 15:08:19.806 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2025-01-03 15:08:19.807 LabApp] JupyterLab extension loaded from /root/miniconda3/envs/python3.13.1/lib/python3.13/site-packages/jupyterlab
[I 2025-01-03 15:08:19.807 LabApp] JupyterLab application directory is /root/miniconda3/envs/python3.13.1/share/jupyter/lab
[I 2025-01-03 15:08:19.807 LabApp] Extension Manager is 'pypi'.
[I 2025-01-03 15:08:19.825 ServerApp] jupyterlab | extension was successfully loaded.
[I 2025-01-03 15:08:19.826 ServerApp] notebook | extension was successfully loaded.
[I 2025-01-03 15:08:19.826 ServerApp] Serving notebooks from local directory: /root/python
[I 2025-01-03 15:08:19.826 ServerApp] Jupyter Server 2.15.0 is running at:
[I 2025-01-03 15:08:19.826 ServerApp] http://registry.ocp.local:8888/tree?token=83ba987b3e4b4e42270650bb2b32c0d8b39eef8dacab3d7e
[I 2025-01-03 15:08:19.826 ServerApp]     http://127.0.0.1:8888/tree?token=83ba987b3e4b4e42270650bb2b32c0d8b39eef8dacab3d7e
[I 2025-01-03 15:08:19.826 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 2025-01-03 15:08:19.828 ServerApp] No web browser found: Error('could not locate runnable browser').
[C 2025-01-03 15:08:19.828 ServerApp] 
    
    To access the server, open this file in a browser:
        file:///root/.local/share/jupyter/runtime/jpserver-1149459-open.html
    Or copy and paste one of these URLs:
        http://192.168.21.184:8888/tree?token=83ba987b3e4b4e42270650bb2b32c0d8b39eef8dacab3d7e
        http://127.0.0.1:8888/tree?token=83ba987b3e4b4e42270650bb2b32c0d8b39eef8dacab3d7e
[I 2025-01-03 15:08:19.834 ServerApp] Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, python-lsp-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server
5. 安装扩展功能(可选)

为提升使用体验,可以安装 Jupyter Notebook 扩展工具。

bash 复制代码
conda install -c conda-forge jupyter_contrib_nbextensions
jupyter contrib nbextension install --user

启用常用扩展:

bash 复制代码
jupyter nbextension enable <extension_name>
6. 更新与维护

定期更新 Jupyter Notebook 以获取最新功能和修复:

bash 复制代码
conda update notebook

删除虚拟环境(如果不再需要):

bash 复制代码
conda remove -n jupyter_env --all
7. 总结

通过 Conda 安装 Jupyter Notebook 是一种快速而高效的方式,尤其适合需要管理多个 Python 环境的用户。您可以根据需求创建独立环境,并灵活扩展 Jupyter 的功能,从而提升开发效率。

相关推荐
The Future is mine12 分钟前
Python计算经纬度两点之间距离
开发语言·python
Enti7c13 分钟前
HTML5和CSS3的一些特性
开发语言·css3
九月镇灵将14 分钟前
GitPython库快速应用入门
git·python·gitpython
爱吃巧克力的程序媛20 分钟前
在 Qt 创建项目时,Qt Quick Application (Compat) 和 Qt Quick Application
开发语言·qt
兔子的洋葱圈1 小时前
【django】1-2 django项目的请求处理流程(详细)
后端·python·django
独好紫罗兰1 小时前
洛谷题单3-P5719 【深基4.例3】分类平均-python-流程图重构
开发语言·python·算法
27669582921 小时前
美团民宿 mtgsig 小程序 mtgsig1.2 分析
java·python·小程序·美团·mtgsig·mtgsig1.2·美团民宿
橘子在努力1 小时前
【橘子大模型】关于PromptTemplate
python·ai·llama
篝火悟者1 小时前
自学-C语言-基础-数组、函数、指针、结构体和共同体、文件
c语言·开发语言
SheepMeMe1 小时前
蓝桥杯2024省赛PythonB组——日期问题
python·算法·蓝桥杯