如何在 PowerShell 中为 "jupyter notebook" 设置别名?
How to set alias for "jupyter notebook" in PowerShell?
每次我想启动 ipython 笔记本时,我必须在 Windows 命令行 cmd
或 powershell
中键入 "jupyter notebook"。是否可以设置别名?我试图在 powershell
:
中做到这一点
New-Alias nb "jupyter notebook"
nb
失败,因为 powershell
无法将 jupyter notebook
识别为 cmdlet 或函数。
那么如何设置别名并保存在powershell
中呢?在 Windows 上开始 ipython notebook
有什么更好的主意吗?
您需要包含可执行文件的路径而不是 "jupyter notebook",因为该程序不在您的 $env:path 中。
new-alias nb "C:\SomePath\JupyterNotebook.exe"
并且您需要将这一行放在您的 Powershell 配置文件中 (~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1),以便它在您每次启动 Powershell 时运行。
首先,打开您的 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
,它会 运行s Jupyter Notebook(jupyter-notebook
命令)。
另一种方法是在 $profile 文件中创建一个函数:
function jn()
{
jupyter notebook
}
每次我想启动 ipython 笔记本时,我必须在 Windows 命令行 cmd
或 powershell
中键入 "jupyter notebook"。是否可以设置别名?我试图在 powershell
:
New-Alias nb "jupyter notebook"
nb
失败,因为 powershell
无法将 jupyter notebook
识别为 cmdlet 或函数。
那么如何设置别名并保存在powershell
中呢?在 Windows 上开始 ipython notebook
有什么更好的主意吗?
您需要包含可执行文件的路径而不是 "jupyter notebook",因为该程序不在您的 $env:path 中。
new-alias nb "C:\SomePath\JupyterNotebook.exe"
并且您需要将这一行放在您的 Powershell 配置文件中 (~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1),以便它在您每次启动 Powershell 时运行。
首先,打开您的 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
,它会 运行s Jupyter Notebook(jupyter-notebook
命令)。
另一种方法是在 $profile 文件中创建一个函数:
function jn()
{
jupyter notebook
}