Skip to content

Instantly share code, notes, and snippets.

@ezwiefel
Last active May 6, 2024 12:02
Show Gist options
  • Save ezwiefel/a295f5b3d6c4c7985819c65746d1f676 to your computer and use it in GitHub Desktop.
Save ezwiefel/a295f5b3d6c4c7985819c65746d1f676 to your computer and use it in GitHub Desktop.
Azure Machine Learning environment as Conda kernel in Jupyter / Jupyterlab
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Create an AzureML Environment as a local Conda kernel in your Jupyter / JupyterLab"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1. Download the Conda Dependencies file from AzureML"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"from azureml.core import Workspace, Environment\n",
"\n",
"ws = Workspace.from_config()\n",
"\n",
"tf_env = Environment.get(ws, 'AzureML-TensorFlow-2.0-GPU')\n",
"tf_env.python.conda_dependencies.save(\"./CondaDependencies.yaml\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"CONDA_ENV_NAME = 'amltf2'\n",
"KERNEL_DISPLAY_NAME = 'AzureML - TensorFlow-2.0 - GPU'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2. Create the Conda Environment"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"%conda env create --name {CONDA_ENV_NAME} --file ./CondaDependencies.yaml"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 3. Install ipykernel in the new Conda environment"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"%conda install -n {CONDA_ENV_NAME} ipykernel -y"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 4. Run ipykernel in the new Conda environment to register the kernelspec"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!/anaconda/envs/{CONDA_ENV_NAME}/bin/python -m ipykernel install --user --name {CONDA_ENV_NAME} --display-name \"{KERNEL_DISPLAY_NAME}\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 5. Wait for a few minutes and the new kernel will show up in Jupyter/Jupyterlab under the available kernels"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.6 - AzureML",
"language": "python",
"name": "python3-azureml"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
@GuetarniTarik
Copy link

GuetarniTarik commented May 6, 2024

Hello @ezwiefel ,

I've tried to setup AzureML Env as Conda Kernel in Jupiter but unfornunately i have an error message on jupiter notebook user interface on AML depiste being able to correctly activate env on terminal interface

Capture d'écran 2024-05-06 113851

FYI, my Azure ML workspace is behind a VNET

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment