{ "cells": [ { "cell_type": "markdown", "id": "052d5df9", "metadata": {}, "source": [ "# IPython examples" ] }, { "cell_type": "markdown", "id": "ddab5ceb", "metadata": {}, "source": [ "## Running Python code" ] }, { "cell_type": "markdown", "id": "bf1366c2", "metadata": {}, "source": [ "### Show Python version" ] }, { "cell_type": "code", "execution_count": 1, "id": "350b0b1f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "sys.version_info(major=3, minor=13, micro=0, releaselevel='final', serial=0)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import sys\n", "\n", "\n", "sys.version_info" ] }, { "cell_type": "markdown", "id": "85985c4b", "metadata": {}, "source": [ "### Show versions of Python packages\n", "\n", "Most Python packages provide a `__version__` method for this:" ] }, { "cell_type": "code", "execution_count": 2, "id": "07dbedd0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'2.2.3'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "\n", "pd.__version__" ] }, { "cell_type": "markdown", "id": "f8603063", "metadata": {}, "source": [ "Alternatively, you can use `version` from `importlib_metadata`:" ] }, { "cell_type": "code", "execution_count": 3, "id": "59e1742e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2.2.3\n" ] } ], "source": [ "from importlib.metadata import version\n", "\n", "print(version(\"pandas\"))" ] }, { "cell_type": "markdown", "id": "190d253a", "metadata": {}, "source": [ "### Information about the host operating system and the versions of installed Python packages" ] }, { "cell_type": "code", "execution_count": 4, "id": "65edc94b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "INSTALLED VERSIONS\n", "------------------\n", "commit : 0691c5cf90477d3503834d983f69350f250a6ff7\n", "python : 3.13.0\n", "python-bits : 64\n", "OS : Darwin\n", "OS-release : 24.0.0\n", "Version : Darwin Kernel Version 24.0.0: Tue Sep 24 23:37:36 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6020\n", "machine : arm64\n", "processor : arm\n", "byteorder : little\n", "LC_ALL : None\n", "LANG : de_DE.UTF-8\n", "LOCALE : de_DE.UTF-8\n", "\n", "pandas : 2.2.3\n", "numpy : 2.1.2\n", "pytz : 2024.2\n", "dateutil : 2.9.0.post0\n", "pip : None\n", "…" ] } ], "source": [ "pd.show_versions()" ] }, { "cell_type": "markdown", "id": "cf1ad941", "metadata": {}, "source": [ "### Only use Python versions ≥ 3.9" ] }, { "cell_type": "code", "execution_count": 5, "id": "9525b5f6", "metadata": {}, "outputs": [], "source": [ "import sys\n", "\n", "\n", "assert sys.version_info[:2] >= (3, 9)" ] }, { "cell_type": "markdown", "id": "c01a8834", "metadata": {}, "source": [ "## Shell commands" ] }, { "cell_type": "code", "execution_count": 6, "id": "64f57ba2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Python 3.13.0\n" ] } ], "source": [ "!python3 -V" ] }, { "cell_type": "markdown", "id": "e3a8bd57", "metadata": {}, "source": [ "## Tab completion" ] }, { "cell_type": "markdown", "id": "bd5fee20", "metadata": {}, "source": [ "… for objects with methods and attributes:\n", "\n", "" ] }, { "cell_type": "markdown", "id": "ede967a8", "metadata": {}, "source": [ "… and also for modules:\n", "\n", "" ] }, { "cell_type": "markdown", "id": "2c53fb80", "metadata": {}, "source": [ "