{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Installating Octave" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import sys\n", "import io\n", "import re" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import urllib.request as request # Python 3" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# get latest stable release download link \n", "base_url = \"https://ftpmirror.gnu.org/octave/windows//"\n", "g = request.urlopen(base_url)\n", "s = g.read().decode()\n", "g.close;\n", "\n", "r = r'(octave-\\d\\.\\d\\.\\d-w64.zip)'\n", "octave_version = re.findall(r,s)[-1][0:-8]\n", "ziplink64bit = base_url+octave_version+\"-w64.zip\"\n", "octave_zip_fullpath = os.path.join(os.environ[\"WINPYDIRBASE\"], \"t\", octave_version+\"-w64.zip\")\n", "siglink64bit = ziplink64bit+\".sig\" # check of pgp signature not implemented\n", "print(\"Octave Version: \"+octave_version)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# start download\n", "g = request.urlopen(ziplink64bit) \n", "with io.open(octave_zip_fullpath, 'wb') as f:\n", " f.write(g.read())\n", "g.close\n", "g = None" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#checking it's there\n", "assert os.path.isfile(octave_zip_fullpath)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#extract the zip archive\n", "import zipfile\n", "try:\n", " with zipfile.ZipFile(octave_zip_fullpath) as z:\n", " z.extractall(os.path.join(os.environ[\"WINPYDIRBASE\"], \"t\"))\n", " print(\"Extracted all files\")\n", "except:\n", " print(\"Invalid file\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# delete zip file\n", "os.remove(octave_zip_fullpath)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Prepare environment variables\n", "os.environ[\"OCTAVE_EXECUTABLE\"] = os.path.join(os.environ[\"WINPYDIRBASE\"], \"t\", octave_version+\"-w64\", \"mingw64\", \"bin\", \"octave-cli.exe\")\n", "os.environ[\"OCTAVE_KERNEL_JSON\"] = os.path.join(os.environ[\"WINPYDIR\"], \"share\", \"jupyter\", \"kernels\", \"octave\", \"kernel.json\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Installing iOctave via pip\n", "!start cmd /C pip install octave_kernel" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# add octave environment variables to the Jupyter Environment\n", "inp_str = r\"\"\"\n", "rem ******************\n", "rem handle {0} if included\n", "rem ******************\n", "if not exist \"%WINPYDIRBASE%\\t\\{0}-w64\" goto {0}_bad\n", "set OCTAVE_EXECUTABLE=%WINPYDIRBASE%\\t\\{0}-w64\\mingw64\\bin\\octave-cli.exe\n", "set OCTAVE_KERNEL_JSON=%WINPYDIR%\\share\\jupyter\\kernels\\octave\\kernel.json\n", ":{0}_bad\n", "\"\"\".format(octave_version)\n", "\n", "# append to env.bat\n", "with open(os.path.join(os.environ[\"WINPYDIRBASE\"],\"scripts\",\"env.bat\"), 'a') as file :\n", " file.write(inp_str)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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.2" } }, "nbformat": 4, "nbformat_minor": 4 }