Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom environment for Racket Programming language #223

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
145 changes: 145 additions & 0 deletions custom-environments/racket-lang/1-install-racket.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "d933b4c6-7f11-454d-bf6a-72c4039da306",
"metadata": {},
"source": [
"# Installing Racket in SageMaker Studio Lab\n",
"\n",
"\n",
"[![Open In Studio Lab](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/aws/studio-lab-examples/blob/main/custom-environments/racket-lang/1-install-racket.ipynb)\n",
"\n",
"This notebook will demonstrate installing a recent version of Racket (currently 8.3) and an associated Racket kernel."
]
},
{
"cell_type": "markdown",
"id": "56047c30-b329-468e-b152-5529693bd2bd",
"metadata": {
"tags": []
},
"source": [
"## 1. Creating a Conda environment for Racket\n",
"\n",
"Installing Racket and associated packages in a conda environment helps keep the rest of your SageMaker Studio Lab environment pristine, and avoids the potential for conflicting packages. Here we create the environment with necessary dependencies preinstalled."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c1aadb0a-4e7e-47cb-b005-8ee841be487c",
"metadata": {},
"outputs": [],
"source": [
"%system conda create -n racket-lang zeromq cairo libjpeg-turbo pango"
]
},
{
"cell_type": "markdown",
"id": "974ca00c-0030-463e-a638-4320e02ad44e",
"metadata": {},
"source": [
"To find shared libraries installed via conda, we need to ensure that the LD_LIBRARY_PATH environment variable is set when our racket-lang environment is activated."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c7a93ef0-565a-478a-b457-15af48582f6d",
"metadata": {},
"outputs": [],
"source": [
"%system conda run -n racket-lang bash -c 'mkdir -p $CONDA_PREFIX/etc/conda/activate.d $CONDA_PREFIX/etc/conda/deactivate.d'\n",
"%system conda run -n racket-lang bash -c 'echo \"export LD_LIBRARY_PATH=$CONDA_PREFIX/lib\" > $CONDA_PREFIX/etc/conda/activate.d/envar.sh'\n",
"%system conda run -n racket-lang bash -c 'echo \"unset LD_LIBRARY_PATH\" > $CONDA_PREFIX/etc/conda/deactivate.d/envar.sh'"
]
},
{
"cell_type": "markdown",
"id": "1bbab127-822a-44ab-a2a5-644b1b890f30",
"metadata": {
"tags": []
},
"source": [
"## 2. Downloading and installing Racket\n",
"\n",
"Racket is available either via direct download or via the Conda package manager. Here we demonstrate installing the official Racket release, as the Conda package of Racket tends to lag official releases. Racket is self-contained and is as simple as downloading, and running the installer."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c7558cf2-f813-492f-8991-a60680bda389",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"%system curl -L https://download.racket-lang.org/installers/8.9/racket-8.9-x86_64-linux-cs.sh -o /tmp/racket-install; chmod +x /tmp/racket-install\n",
"%system conda run -n racket-lang bash -c '/tmp/racket-install --unix-style --create-dir --dest $CONDA_PREFIX'; rm /tmp/racket-install"
]
},
{
"cell_type": "markdown",
"id": "bec6f61c-1156-46d3-ade6-d7562ed409fa",
"metadata": {},
"source": [
"## 3. Install the IRacket kernel\n",
"\n",
"Installing the IRacket kernel is similiarly simple. Here we use the `raco` package manager to install the IRacket kernel. Note that the `-i` flag to raco ensures the packages install to the version of raco we installed in our conda environment. If installing additional packages from e.g. the terminal, make sure to activate the racket-lang using `conda activate racket-lang` and then be sure to include the `-i` flag to `raco` for any Racket packages you wish to install."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "961e9baa-0584-4eb7-a244-feeff7e6cb8f",
"metadata": {},
"outputs": [],
"source": [
"%system conda run -n racket-lang raco pkg install -i --auto iracket aws"
]
},
{
"cell_type": "markdown",
"id": "670b5c00-3b24-4494-9db6-9c22f7cc703f",
"metadata": {},
"source": [
"After installing the iracket package (and any other packages we wish to install), we run the iracket package's setup script and ensure the IRacket kernel is moved to the correct directory."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "78fbd80a-b54e-4604-9186-38ac73d85ea5",
"metadata": {},
"outputs": [],
"source": [
"%system conda run -n racket-lang raco iracket install\n",
"%system conda run -n racket-lang bash -c 'mkdir -p $CONDA_PREFIX/share/jupyter/kernels/racket'\n",
"%system conda run -n racket-lang bash -c 'mv ~/.local/share/jupyter/kernels/racket/* $CONDA_PREFIX/share/jupyter/kernels/racket/; rm -r ~/.local/share/jupyter/kernels/racket; rm -rf /home/studio-lab-user/.conda/envs/default/share/jupyter/kernels/racket'"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "default:Python",
"language": "python",
"name": "conda-env-default-py"
},
"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.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading