แก้ไข

แชร์ผ่าน


Access a compute instance terminal in your workspace

Access the terminal of a compute instance in your workspace to:

  • Use files from Git and version files. These files are stored in your workspace file system, not restricted to a single compute instance.
  • Install packages on the compute instance.
  • Create extra kernels on the compute instance.

Prerequisites

Access a terminal

To access the terminal:

  1. Open your workspace in Azure Machine Learning studio.

  2. On the left side, select Notebooks.

  3. Select the Open terminal image.

    Open terminal window

  4. When a compute instance is running, the terminal window for that compute instance appears.

  5. When no compute instance is running, use the Compute section to start or create a compute instance. Start or create a compute instance

In addition to the previous steps, you can also access the terminal from:

  • In VS Code: Select the Terminal > New Terminal from the menu. The entry may be hidden behind ... in menu. To learn more about connecting to your workspace from VS Code, see Work in VS Code remotely connected to a compute instance.
  • RStudio or Posit Workbench (formerly RStudio Workbench) (See Add custom applications such as RStudio or Posit Workbench)): Select the Terminal tab on top left.
  • Jupyter Lab: Select the Terminal tile under the Other heading in the Launcher tab.
  • Jupyter: Select New>Terminal on top right in the Files tab.
  • SSH to the machine, if you enabled SSH access when the compute instance was created. If the compute instance is in a managed virtual network and doesn't have a public IP address, use the az ml compute connect-ssh command to connect to the compute instance.

Copy and paste in the terminal

In the Notebooks section, you can copy and paste text between the terminal and the notebook cells.

  • Windows: Ctrl-c to copy and use Ctrl-v or Ctrl-Shift-v or Shift-Insert to paste.
  • Mac OS: Cmd-c to copy and Cmd-v to paste.
  • FireFox and Internet Explorer may not support clipboard permissions properly.

Use files from Git and version files

Access all Git operations from the terminal. All Git files and folders are stored in your workspace file system. This storage allows you to use these files from any compute instance in your workspace.

Note

Add your files and folders anywhere under the ~/cloudfiles/code/Users folder so they will be visible in all your Jupyter environments.

To integrate Git with your Azure Machine Learning workspace, see Git integration for Azure Machine Learning.

Install packages

Install packages from a terminal window. Install packages into the kernel that you want to use to run your notebooks. The default kernel is python310-sdkv2.

Or you can install packages directly in Jupyter Notebook, RStudio, or Posit Workbench (formerly RStudio Workbench):

Note

For package management within a Python notebook, use %pip or %conda magic functions to automatically install packages into the currently-running kernel, rather than !pip or !conda which refers to all packages (including packages outside the currently-running kernel)

Add new kernels

Warning

While customizing the compute instance, make sure you do not delete conda environments or jupyter kernels that you didn't create. Doing so may damage Jupyter/JupyterLab functionality.

To add a new Jupyter kernel to the compute instance:

  1. Use the terminal window to create a new environment. For example, the following command creates newenv:

    conda create --name newenv
    
  2. Activate the environment. For example, after creating newenv:

    conda activate newenv
    
  3. Install pip and ipykernel package to the new environment and create a kernel for that conda env

    conda install pip
    conda install ipykernel
    python -m ipykernel install --user --name newenv --display-name "Python (newenv)"
    

Any of the available Jupyter Kernels can be installed.

To add a new R kernel to the compute instance:

  1. Use the terminal window to create a new environment. For example, the following command creates r_env:

    conda create -n r_env r-essentials r-base
    
  2. Activate the environment. For example, after creating r_env:

    conda activate r_env
    
  3. Run R in the new environment:

    R
    
  4. At the R prompt, run IRkernel:

    IRkernel::installspec(name = 'irenv', displayname = 'New R Env')
    
  5. Quit the R session.

    q()
    

It takes a few minutes before the new R kernel is ready to use. If you get an error saying it's invalid, wait and then try again.

For more information about conda, see Using R language with Anaconda. For more information about IRkernel, see Native R kernel for Jupyter.

Remove added kernels

Warning

While customizing the compute instance, make sure you do not delete conda environments or jupyter kernels that you didn't create.

To remove an added Jupyter kernel from the compute instance, you must remove the kernelspec, and (optionally) the conda environment. You can also choose to keep the conda environment. You must remove the kernelspec, or your kernel is still selectable and could cause unexpected behavior.

To remove the kernelspec:

  1. Use the terminal window to list and find the kernelspec:

    jupyter kernelspec list
    
  2. Remove the kernelspec, replacing UNWANTED_KERNEL with the kernel you'd like to remove:

    jupyter kernelspec uninstall UNWANTED_KERNEL
    

To also remove the conda environment:

  1. Use the terminal window to list and find the conda environment:

    conda env list
    
  2. Remove the conda environment, replacing ENV_NAME with the conda environment you'd like to remove:

    conda env remove -n ENV_NAME
    

Upon refresh, the kernel list in your notebooks view should reflect the changes you made.

Manage terminal sessions

Terminal sessions can stay active if terminal tabs aren't properly closed. Too many active terminal sessions can impact the performance of your compute instance.

Select Manage active sessions in the terminal toolbar to see a list of all active terminal sessions and shut down the sessions you no longer need.

Learn more about how to manage sessions running on your compute at Managing notebook and terminal sessions.

Warning

Make sure you close any sessions you no longer need to preserve your compute instance's resources and optimize your performance.