【问题标题】:How to set alias for "jupyter notebook" in PowerShell?如何在 PowerShell 中为“jupyter notebook”设置别名?
【发布时间】:2016-04-27 01:07:02
【问题描述】:

每次我想启动 ipython notebook 时,我都必须在 Windows 命令行cmdpowershell 中输入“jupyter notebook”。是否可以设置别名?我尝试在powershell 中执行此操作:

New-Alias nb "jupyter notebook"

nb 失败,因为 powershell 无法将 jupyter notebook 识别为 cmdlet 或函数。

那么如何设置别名并保存在powershell中呢?在 Windows 上启动 ipython notebook 有更好的主意吗?

【问题讨论】:

  • 可能它不喜欢它,因为它包含一个参数,而不仅仅是可执行文件名称?请改用jupyter-notebook

标签: powershell jupyter-notebook


【解决方案1】:

您需要包含可执行文件的路径而不是“jupyter notebook”,因为该程序不在您的 $env:path 中。

new-alias nb "C:\SomePath\JupyterNotebook.exe"

您需要将此行放在您的 Powershell 配置文件 (~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1) 中,以便每次启动 Powershell 时它都会运行。

【讨论】:

  • 非常感谢。我必须添加:New-Item -path $profile -type file –force 创建配置文件,Set-ExecutionPolicy RemoteSigned 允许执行脚本。
  • 使用 where.exe jupyter-notebook 从 powershell 中找出它的位置。
  • 这不适用于 conda 环境。每个 conda env 都有自己的 jupyter-notebook.exe 文件,但这每次都会运行相同的基本 env 文件。
【解决方案2】:

首先,打开你的 PS 个人资料:

notepad $profile

如果此命令打开记事本并显示“系统找不到指定的路径”对话框,则执行new-item -type file -path $profile -force 并重复命令notepad $profile

然后,你可以添加一个别名:

Set-Alias -Name jn -Value jupyter-notebook

jupyter notebook 命令和jupyter-notebook 应该是等价的。

如果您还没有启用脚本运行,您还需要以管理员身份打开 PowerShell 并运行Set-ExecutionPolicy RemoteSigned。否则你会看到类似File C:\Users\...\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because running scripts is disabled on this system.的错误

现在,当您打开一个新的 PowerShell 时,您可以输入 jn 并运行 Jupyter Notebook(jupyter-notebook 命令)。

另一种方法是在 $profile 文件中创建一个函数:

function jn()
{
    jupyter notebook
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    • 2021-06-14
    • 2022-06-16
    • 2016-10-19
    • 2014-12-01
    • 2021-03-31
    相关资源
    最近更新 更多