
- Jupyter 教程
- Jupyter - 首页
- IPython
- IPython - 简介
- IPython - 安装
- IPython - 开始使用
- 运行和编辑 Python 脚本
- IPython - 历史命令
- IPython - 系统命令
- IPython - 命令行选项
- 动态对象自省
- IPython - I/O 缓存
- 设置 IPython 为默认 Python 环境
- 导入 Python Shell 代码
- IPython - 嵌入 IPython
- IPython - 魔术命令
- Jupyter
- Jupyter 项目 - 概述
- Jupyter Notebook - 简介
- 在线使用 Jupyter
- 安装和开始使用
- Jupyter Notebook - 仪表盘
- Jupyter Notebook - 用户界面
- Jupyter Notebook - 单元格类型
- Jupyter Notebook - 编辑
- Jupyter Notebook - Markdown 单元格
- 单元格魔法函数
- Jupyter Notebook - 绘图
- 转换 Notebook
- Jupyter Notebook - IPyWidgets
- QtConsole
- QtConsole - 开始使用
- QtConsole - 多行编辑
- QtConsole - 内联图形
- QtConsole - 保存为 Html
- QtConsole - 多个控制台
- 连接到 Jupyter Notebook
- 使用 github 和 nbviewer
- Jupyter 资源
- Jupyter - 快速指南
- Jupyter - 有用资源
- Jupyter - 讨论
设置 IPython 为默认 Python 环境
不同的环境变量会影响 Python 的行为。PYTHONSTARTUP 环境变量被赋值给一个 Python 脚本。这样,这个脚本会在 Python 提示符 (>>>) 出现之前执行。如果每次新的 Python 会话启动时都需要默认加载某些模块,这将非常有用。
下面的脚本 (start.py) 导入 IPython 模块并执行 start_ipython() 函数,以将默认的 Python shell (提示符为 >>>)替换为 IPython shell,当调用 Python 可执行文件时。
import os, IPython os.environ['PYTHONSTARTUP'] = '' IPython.start_ipython() raise SystemExit
假设此文件存储在 Python 的安装目录 (c:\python36) 中,设置 PYTHONSTARTUP 环境变量并从命令行启动 Python。然后 IPython shell 将如下所示:

请注意,可以使用 Windows 中的系统属性对话框和 Linux 中的 export 命令永久设置环境变量。
广告