aitech-ium/IUM_09.Python_srodowiska.ipynb

4791 lines
195 KiB
Plaintext
Raw Normal View History

2021-05-24 11:36:41 +02:00
{
"cells": [
{
"cell_type": "markdown",
2021-09-28 10:56:21 +02:00
"id": "4b9b298d",
2021-05-31 11:55:27 +02:00
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
2021-09-28 10:56:21 +02:00
"![Logo 1](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech1.jpg)\n",
"<div class=\"alert alert-block alert-info\">\n",
"<h1> Inżynieria uczenia maszynowego </h1>\n",
"<h2> 9. <i>Środowiska wirtualne</i> [laboratoria]</h2> \n",
2022-05-16 12:13:09 +02:00
"<h3> Tomasz Ziętkiewicz (2022)</h3>\n",
2021-09-28 10:56:21 +02:00
"</div>\n",
"\n",
"![Logo 2](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech2.jpg)"
2021-05-24 11:36:41 +02:00
]
},
{
"cell_type": "markdown",
"id": "cf14c577",
2021-05-31 11:55:27 +02:00
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"## Python Virtual Env\n",
" - Python posiada wbudowany mechanizm do zarządzania wirtualnymi środowiskami\n",
" - Nie mylić z bardziej rozbudowanym [virtualenv](https://pypi.org/project/virtualenv/) (dla Python 2)\n",
" - Umożliwia używanie różnych wersji bibliotek do różnych zastosowań\n",
" - Dotyczy on tylko bibliotek pythona\n",
" - Więcej informacji: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "85284459",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"Poniżej stworzymy środowisko w katalogu `./myenv`:"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "9cabe194",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"```\n",
"$ python3 -m venv myenv\n",
"```"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "2a8b1048",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"Teraz możemy je aktywować:"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "4619a71d",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"```\n",
"$ source ./myenv/bin/activate\n",
"(myenv) $ which python\n",
"/home/tomek/myenv/bin/python\n",
"```"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "2e5bf86a",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"I modyfikować instalując zależności:"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "256149c4",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"```\n",
"(myenv) $ python3 -m pip install requests\n",
"```"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "7fbba7d3",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"Środowisko możemy deaktywować poprzez:"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "a2d688b7",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"```\n",
"deactivate\n",
"```"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "0d3eb6d4",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"Środowisko można udostępnić kopiując cały katalog ze środowiskiem"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "90605b49",
2021-09-28 10:56:21 +02:00
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-31 11:55:27 +02:00
"source": [
"## pipx\n",
" - pipx: polecenie, które instaluje moduł Pythonowy w odrębnym środowisku wirtualnym venv\n",
" - jednocześnie dodaje powiązane z nim polecenie (\"Command line entry point\") do zmiennej `PATH`\n",
" - w ten sposób możemy zainstalować polecenie, które będzie globalnie dostępne a jednocześnie nie będzie \"mieszało\" w zależnościach modułów Pythonowych. Umożliwia to uniknięcie konfliktów między zależnościami i jednocześnie umożliwia dostęp do polecenia oferowanego przez moduł z poziomu systemu (bez ręcznej aktywacji środowiska)\n",
" - więcej informacji: https://packaging.python.org/guides/installing-stand-alone-command-line-tools/\n",
" - https://github.com/pypa/pipx"
]
},
{
"cell_type": "markdown",
2022-05-16 12:13:09 +02:00
"id": "a8aca05d",
2021-05-31 11:55:27 +02:00
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"## Conda\n",
"> *Package, dependency and environment management for any language—Python, R, Ruby, Lua, Scala, Java, JavaScript, C/ C++, FORTRAN, and more.*\n",
"\n",
"<img src=\"img/environments/conda.png\"/>\n",
"\n",
"Conda umożliwia zarządzanie:\n",
" - środowiskami (jak venv)\n",
" - paczkami i zależnościami (jak pip)\n",
"\n",
2022-05-16 12:13:09 +02:00
"Dokumentacja: https://docs.conda.io/en/latest/"
]
},
{
"cell_type": "markdown",
"id": "26f253cb",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
2021-05-24 11:36:41 +02:00
"Różnice między Conda a venv [źródło](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/environments.html#virtual-environments):\n",
" - Dowolna wersja Python w Conda (inna niż systemowa)\n",
" - Conda zarządza też zależnościami innymi niż Pythonowe\n",
2021-05-31 11:55:27 +02:00
" - Paczki w PyPI (używane przez `pip`) pochodzą od ich autorów. Paczki w conda są  budowane przez conda albo społeczność conda-forge"
2021-05-24 11:36:41 +02:00
]
},
{
"cell_type": "markdown",
"id": "57f19a08",
2021-05-31 11:55:27 +02:00
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
2021-05-31 11:55:27 +02:00
"## Dystrybucje: Anaconda i MiniConda\n",
2021-05-24 11:36:41 +02:00
"Conda jest dostępna w dwóch dystrybcjach:\n",
" - [Miniconda](https://docs.conda.io/en/latest/miniconda.html):\n",
" - wymaga 400 MB miejsca na dysku\n",
" - zawiera jedynie podstawowe narzędzia:\n",
" - conda\n",
" - Python\n",
" - pip, zlib\n",
" - pozostałe narzędzia/biblioteki doinstalujemy w miarę potrzeb\n",
" - [Anaconda](https://www.anaconda.com/products/individual)\n",
" - wymaga conajmniej 3 GB miejsca na dysku\n",
" - Zawiera narzędzi GUI [Anaconda Navigator](https://docs.anaconda.com/anaconda/navigator/) (można je doinstalować do Miniconda)\n",
" - zawiera to co Miniconda +:\n",
" - Ponad 1500 preinstalowanych pakietów, głównie \"naukowych\", m.in.: SciPy, NumPy, Jupyter, scikit-learn, Pandas\n",
2022-05-16 12:13:09 +02:00
" - bezpłatna dla użytkowników indywidualnych, małych firm i orgranizacji non-profit (\"Anaconda distribution\")\n",
" - płatna dla dużych firm (+200 osób i instytucji rządowych (\"Anaconda Proferssional\")\n",
2021-05-24 11:36:41 +02:00
" "
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "d6d5156a",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"## Dystrybucje\n",
" - Wersje paczek/bibliotek zawartych w danej dystrybucji są przetestowane pod względem zgodności ze sobą\n",
" - Możemy dokonać zaktualizacji wszystkich pakietów za pomocą polecenia: `conda update conda`\n",
" - Conda zatroszczy się o to, by rozwiązać potencjalne konflikty wynikające z zależności deklarowanych przez poszczególne biblioteki. \n",
" - Nie zawsze wszystkie biblioteki będą w swoich najnowszych wersjach - mogłoby to powodować problemy z działaniem bibliotek od nich zależnych\n",
" - Podczas aktualizacji niektóre biblioteki mogą zostać \"zdowngradowane\""
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "61d89bd2",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"```\n",
"$ conda update conda\n",
"Collecting package metadata (current_repodata.json): done\n",
"Solving environment: done\n",
"\n",
"## Package Plan ##\n",
"\n",
" environment location: /home/tomek/miniconda3\n",
"\n",
" added / updated specs:\n",
" - conda\n",
"\n",
"\n",
"The following packages will be downloaded:\n",
"\n",
" package | build\n",
" ---------------------------|-----------------\n",
" attrs-21.2.0 | pyhd3eb1b0_0 46 KB\n",
" cffi-1.14.5 | py39h261ae71_0 226 KB\n",
" chardet-4.0.0 |py39h06a4308_1003 194 KB\n",
" conda-package-handling-1.7.3| py39h27cfd23_1 884 KB\n",
" cryptography-3.4.7 | py39hd23ed53_0 906 KB\n",
" decorator-5.0.9 | pyhd3eb1b0_0 12 KB\n",
" glib-2.68.2 | h36276a3_0 3.0 MB\n",
" idna-2.10 | pyhd3eb1b0_0 52 KB\n",
" jinja2-3.0.0 | pyhd3eb1b0_0 106 KB\n",
" markupsafe-2.0.1 | py39h27cfd23_0 22 KB\n",
" notebook-6.4.0 | py39h06a4308_0 4.1 MB\n",
" pygments-2.9.0 | pyhd3eb1b0_0 721 KB\n",
" pyopenssl-20.0.1 | pyhd3eb1b0_1 49 KB\n",
" requests-2.25.1 | pyhd3eb1b0_0 52 KB\n",
" ruamel_yaml-0.15.100 | py39h27cfd23_0 260 KB\n",
" tqdm-4.59.0 | pyhd3eb1b0_1 93 KB\n",
" urllib3-1.26.4 | pyhd3eb1b0_0 105 KB\n",
" ------------------------------------------------------------\n",
" Total: 10.7 MB\n",
"\n",
"The following packages will be REMOVED:\n",
"\n",
" libedit-3.1.20191231-h14c3975_1\n",
" pip-20.3.1-py39h06a4308_0\n",
" wheel-0.36.1-pyhd3eb1b0_0\n",
"\n",
"The following packages will be UPDATED:\n",
"\n",
" attrs 20.3.0-pyhd3eb1b0_0 --> 21.2.0-pyhd3eb1b0_0\n",
" ca-certificates conda-forge::ca-certificates-2020.12.~ --> pkgs/main::ca-certificates-2021.4.13-h06a4308_1\n",
" cffi 1.14.4-py39h261ae71_0 --> 1.14.5-py39h261ae71_0\n",
" chardet 3.0.4-py39h06a4308_1003 --> 4.0.0-py39h06a4308_1003\n",
" conda conda-forge::conda-4.10.1-py39hf3d152~ --> pkgs/main::conda-4.10.1-py39h06a4308_1\n",
" conda-package-han~ 1.7.2-py39h27cfd23_1 --> 1.7.3-py39h27cfd23_1\n",
" cryptography 3.3.1-py39h3c74f83_0 --> 3.4.7-py39hd23ed53_0\n",
" decorator 5.0.6-pyhd3eb1b0_0 --> 5.0.9-pyhd3eb1b0_0\n",
" glib 2.68.1-h36276a3_0 --> 2.68.2-h36276a3_0\n",
" jinja2 2.11.3-pyhd3eb1b0_0 --> 3.0.0-pyhd3eb1b0_0\n",
" markupsafe 1.1.1-py39h27cfd23_0 --> 2.0.1-py39h27cfd23_0\n",
" notebook 6.3.0-py39h06a4308_0 --> 6.4.0-py39h06a4308_0\n",
" pygments 2.8.1-pyhd3eb1b0_0 --> 2.9.0-pyhd3eb1b0_0\n",
" pyopenssl 20.0.0-pyhd3eb1b0_1 --> 20.0.1-pyhd3eb1b0_1\n",
" readline 8.0-h7b6447c_0 --> 8.1-h27cfd23_0\n",
" requests 2.25.0-pyhd3eb1b0_0 --> 2.25.1-pyhd3eb1b0_0\n",
" ruamel_yaml 0.15.80-py39h27cfd23_0 --> 0.15.100-py39h27cfd23_0\n",
" setuptools 51.0.0-py39h06a4308_2 --> 52.0.0-py39h06a4308_0\n",
" sqlite 3.33.0-h62c20be_0 --> 3.35.4-hdfb4753_0\n",
" tqdm 4.54.1-pyhd3eb1b0_0 --> 4.59.0-pyhd3eb1b0_1\n",
" tzdata 2020d-h14c3975_0 --> 2020f-h52ac0ba_0\n",
" urllib3 1.25.11-py_0 --> 1.26.4-pyhd3eb1b0_0\n",
"\n",
"The following packages will be SUPERSEDED by a higher-priority channel:\n",
"\n",
" certifi conda-forge::certifi-2020.12.5-py39hf~ --> pkgs/main::certifi-2020.12.5-py39h06a4308_0\n",
"\n",
"The following packages will be DOWNGRADED:\n",
"\n",
" idna 2.10-py_0 --> 2.10-pyhd3eb1b0_0\n",
"\n",
"\n",
"Proceed ([y]/n)? y\n",
"\n",
"[...]\n",
"\n",
"\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "1c7b2930",
2021-05-31 11:55:27 +02:00
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"## Instalacja\n",
"Instrukcje: \n",
"- [Linux](https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html)\n",
"- [Windows](https://docs.conda.io/projects/conda/en/latest/user-guide/install/windows.html)\n",
"- [macOS](https://docs.conda.io/projects/conda/en/latest/user-guide/install/macos.html)"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "0ceff229",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"## Pakiety Conda\n",
"Pakiet (Package) conda to archiwum o rozszerzeniu `.tar.bz2` lub `.conda`zawierające:\n",
" - folder `lib`: biblioteki systemowe, moduły Python\n",
" - folder `bin`: pliki wykonywalne i wszelkie inne pliki potrzebne to zainstalowania danej zależności\n",
" - metadane w katalogu `info/`\n",
" \n",
" \n",
" \n",
"Pakiety można:\n",
" - wyszukiwać: `conda search pytorch`\n",
" - instalować: `conda install pytorch`\n",
" - tworzyć: `conda build hello_world`\n",
" - usuwać: `conda remove pytorch`\n",
" "
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "f54f3bdb",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"### Repozytoria i kanały\n",
"- Pakiety mogą być ściągane z różnych kanałów (\"channels\")\n",
"- Kanały mogą być zdalne albo lokalne\n",
"- Domyślny kanał to https://repo.anaconda.com/pkgs/ - zawiera ponad 7,5 tys pakietów, jest utrzymywany przez Anacondę.\n",
"- Jeśli jakiejś paczki nie ma na oficjalnym kanale, bardzo możliwe, że znajdziemy ją na [Conda-forge](https://conda-forge.org/) - kanale utrzymywanym przez społeczność\n",
"- Wyszukiwanie i przeglądanie pakietów: [conda i conda-forge](https://anaconda.org/anaconda/repo)"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "5ab846d0",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"Na przykład, pakiet `mlflow` nie jest dostępny na oficjalnym kanale:"
]
},
{
"cell_type": "code",
"execution_count": 6,
2021-05-31 11:55:27 +02:00
"id": "f301bdf7",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loading channels: done\n",
"No match found for: mlflow. Search: *mlflow*\n",
"\n",
"PackagesNotFoundError: The following packages are not available from current channels:\n",
"\n",
" - mlflow\n",
"\n",
"Current channels:\n",
"\n",
" - https://repo.anaconda.com/pkgs/main/linux-64\n",
" - https://repo.anaconda.com/pkgs/main/noarch\n",
" - https://repo.anaconda.com/pkgs/r/linux-64\n",
" - https://repo.anaconda.com/pkgs/r/noarch\n",
"\n",
"To search for alternate channels that may provide the conda package you're\n",
"looking for, navigate to\n",
"\n",
" https://anaconda.org\n",
"\n",
"and use the search bar at the top of the page.\n",
"\n",
"\n",
"\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"conda search mlflow"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "ea36f2cd",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"Do poleceń `search` i `install` możemy dodać flagę `channel` co doda podany kanał do listy przeszukiwanych przez to polecenie kanałów:"
]
},
{
"cell_type": "code",
"execution_count": 7,
2021-05-31 11:55:27 +02:00
"id": "61911bf5",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loading channels: done\n",
"# Name Version Build Channel \n",
"mlflow 0.9.0.1 py_0 conda-forge \n",
"mlflow 0.9.1 py_0 conda-forge \n",
"mlflow 1.0.0 py27_0 conda-forge \n",
"mlflow 1.0.0 py27_1 conda-forge \n",
"mlflow 1.0.0 py_2 conda-forge \n",
"mlflow 1.0.0 py_3 conda-forge \n",
"mlflow 1.1.0 py_0 conda-forge \n",
"mlflow 1.2.0 py_0 conda-forge \n",
"mlflow 1.2.0 py_1 conda-forge \n",
"mlflow 1.3.0 py36_0 conda-forge \n",
"mlflow 1.3.0 py37_0 conda-forge \n",
"mlflow 1.4.0 py36_0 conda-forge \n",
"mlflow 1.4.0 py37_0 conda-forge \n",
"mlflow 1.4.0 py38_0 conda-forge \n",
"mlflow 1.5.0 py36_0 conda-forge \n",
"mlflow 1.5.0 py36_1 conda-forge \n",
"mlflow 1.5.0 py37_0 conda-forge \n",
"mlflow 1.5.0 py37_1 conda-forge \n",
"mlflow 1.5.0 py38_0 conda-forge \n",
"mlflow 1.5.0 py38_1 conda-forge \n",
"mlflow 1.6.0 py36_0 conda-forge \n",
"mlflow 1.6.0 py37_0 conda-forge \n",
"mlflow 1.6.0 py38_0 conda-forge \n",
"mlflow 1.7.0 py36_0 conda-forge \n",
"mlflow 1.7.0 py37_0 conda-forge \n",
"mlflow 1.7.0 py38_0 conda-forge \n",
"mlflow 1.7.1 py36h9f0ad1d_0 conda-forge \n",
"mlflow 1.7.1 py37hc8dfbb8_0 conda-forge \n",
"mlflow 1.7.1 py38h32f6830_0 conda-forge \n",
"mlflow 1.7.2 py36h9f0ad1d_0 conda-forge \n",
"mlflow 1.7.2 py37hc8dfbb8_0 conda-forge \n",
"mlflow 1.7.2 py38h32f6830_0 conda-forge \n",
"mlflow 1.8.0 py36h9f0ad1d_0 conda-forge \n",
"mlflow 1.8.0 py37hc8dfbb8_0 conda-forge \n",
"mlflow 1.8.0 py38h32f6830_0 conda-forge \n",
"mlflow 1.9.1 py36h9f0ad1d_0 conda-forge \n",
"mlflow 1.9.1 py37hc8dfbb8_0 conda-forge \n",
"mlflow 1.9.1 py38h32f6830_0 conda-forge \n",
"mlflow 1.10.0 py36h9f0ad1d_0 conda-forge \n",
"mlflow 1.10.0 py37hc8dfbb8_0 conda-forge \n",
"mlflow 1.10.0 py38h32f6830_0 conda-forge \n",
"mlflow 1.11.0 py36h9f0ad1d_0 conda-forge \n",
"mlflow 1.11.0 py36h9f0ad1d_1 conda-forge \n",
"mlflow 1.11.0 py37hc8dfbb8_0 conda-forge \n",
"mlflow 1.11.0 py37hc8dfbb8_1 conda-forge \n",
"mlflow 1.11.0 py38h32f6830_0 conda-forge \n",
"mlflow 1.11.0 py38h32f6830_1 conda-forge \n",
"mlflow 1.12.0 py36h5fab9bb_0 conda-forge \n",
"mlflow 1.12.0 py37h89c1867_0 conda-forge \n",
"mlflow 1.12.0 py38h578d9bd_0 conda-forge \n",
"mlflow 1.12.1 py36h5fab9bb_0 conda-forge \n",
"mlflow 1.12.1 py37h89c1867_0 conda-forge \n",
"mlflow 1.12.1 py38h578d9bd_0 conda-forge \n",
"mlflow 1.13 py36h5fab9bb_0 conda-forge \n",
"mlflow 1.13 py37h89c1867_0 conda-forge \n",
"mlflow 1.13 py38h578d9bd_0 conda-forge \n",
"mlflow 1.13.1 py36h5fab9bb_0 conda-forge \n",
"mlflow 1.13.1 py36h5fab9bb_2 conda-forge \n",
"mlflow 1.13.1 py36hd000896_2 conda-forge \n",
"mlflow 1.13.1 py37h89c1867_0 conda-forge \n",
"mlflow 1.13.1 py37h89c1867_2 conda-forge \n",
"mlflow 1.13.1 py38h578d9bd_0 conda-forge \n",
"mlflow 1.13.1 py38h578d9bd_2 conda-forge \n",
"mlflow 1.13.1 py39hf3d152e_2 conda-forge \n",
"mlflow 1.14.0 py36h24e63a9_1 conda-forge \n",
"mlflow 1.14.0 py36h5fab9bb_0 conda-forge \n",
"mlflow 1.14.0 py36h87b8279_1 conda-forge \n",
"mlflow 1.14.0 py36hd000896_0 conda-forge \n",
"mlflow 1.14.0 py37h02d9ccd_1 conda-forge \n",
"mlflow 1.14.0 py37h89c1867_0 conda-forge \n",
"mlflow 1.14.0 py38h578d9bd_0 conda-forge \n",
"mlflow 1.14.0 py38he918c71_1 conda-forge \n",
"mlflow 1.14.0 py39ha39b057_1 conda-forge \n",
"mlflow 1.14.0 py39hf3d152e_0 conda-forge \n",
"mlflow 1.14.1 py36h24e63a9_0 conda-forge \n",
"mlflow 1.14.1 py36h87b8279_0 conda-forge \n",
"mlflow 1.14.1 py37h02d9ccd_0 conda-forge \n",
"mlflow 1.14.1 py38he918c71_0 conda-forge \n",
"mlflow 1.14.1 py39ha39b057_0 conda-forge \n",
"mlflow 1.15.0 py36h24e63a9_0 conda-forge \n",
"mlflow 1.15.0 py36h87b8279_0 conda-forge \n",
"mlflow 1.15.0 py37h02d9ccd_0 conda-forge \n",
"mlflow 1.15.0 py38he918c71_0 conda-forge \n",
"mlflow 1.15.0 py39ha39b057_0 conda-forge \n",
"mlflow 1.16.0 py36h24e63a9_0 conda-forge \n",
"mlflow 1.16.0 py36h87b8279_0 conda-forge \n",
"mlflow 1.16.0 py37h02d9ccd_0 conda-forge \n",
"mlflow 1.16.0 py38he918c71_0 conda-forge \n",
"mlflow 1.16.0 py39ha39b057_0 conda-forge \n",
"mlflow 1.17.0 py36h24e63a9_0 conda-forge \n",
"mlflow 1.17.0 py36h24e63a9_1 conda-forge \n",
"mlflow 1.17.0 py36h87b8279_0 conda-forge \n",
"mlflow 1.17.0 py36h87b8279_1 conda-forge \n",
"mlflow 1.17.0 py37h02d9ccd_0 conda-forge \n",
"mlflow 1.17.0 py37h02d9ccd_1 conda-forge \n",
"mlflow 1.17.0 py38he918c71_0 conda-forge \n",
"mlflow 1.17.0 py38he918c71_1 conda-forge \n",
"mlflow 1.17.0 py39ha39b057_0 conda-forge \n",
"mlflow 1.17.0 py39ha39b057_1 conda-forge \n",
"\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"conda search mlflow --channel conda-forge"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "c7cea2c5",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"Możemy dodać kanał `conda-forge` tak, żeby był używany automatycznie (bez podawania flagi `channel`):"
]
},
{
"cell_type": "code",
"execution_count": 11,
2021-05-31 11:55:27 +02:00
"id": "df31755c",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Warning: 'conda-forge' already in 'channels' list, moving to the top\n",
"\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"conda config --add channels conda-forge"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "33b4d692",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"Polecanie `conda info` pokaże nam m.in. używane domyślnie kanały.\n",
"Możem dodawać i usuwać kanały oraz zmieniać ich kolejność (priorytet) edytując plik [`~/.condarc`](https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html)"
]
},
{
"cell_type": "code",
"execution_count": 10,
2021-05-31 11:55:27 +02:00
"id": "b5621afa",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" active environment : base\n",
" active env location : /home/tomek/miniconda3\n",
" shell level : 1\n",
" user config file : /home/tomek/.condarc\n",
" populated config files : /home/tomek/.condarc\n",
" conda version : 4.10.1\n",
" conda-build version : not installed\n",
" python version : 3.9.1.final.0\n",
" virtual packages : __cuda=11.2=0\n",
" __linux=5.4.0=0\n",
" __glibc=2.31=0\n",
" __unix=0=0\n",
" __archspec=1=x86_64\n",
" base environment : /home/tomek/miniconda3 (writable)\n",
" conda av data dir : /home/tomek/miniconda3/etc/conda\n",
" conda av metadata url : https://repo.anaconda.com/pkgs/main\n",
" channel URLs : https://conda.anaconda.org/conda-forge/linux-64\n",
" https://conda.anaconda.org/conda-forge/noarch\n",
" https://repo.anaconda.com/pkgs/main/linux-64\n",
" https://repo.anaconda.com/pkgs/main/noarch\n",
" https://repo.anaconda.com/pkgs/r/linux-64\n",
" https://repo.anaconda.com/pkgs/r/noarch\n",
" package cache : /home/tomek/miniconda3/pkgs\n",
" /home/tomek/.conda/pkgs\n",
" envs directories : /home/tomek/miniconda3/envs\n",
" /home/tomek/.conda/envs\n",
" platform : linux-64\n",
" user-agent : conda/4.10.1 requests/2.25.1 CPython/3.9.1 Linux/5.4.0-73-generic ubuntu/20.04.2 glibc/2.31\n",
" UID:GID : 1000:1000\n",
" netrc file : None\n",
" offline mode : False\n",
"\n",
"\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"conda info"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "cb1df295",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"Jak widać, po dodaniu kanału `conda-forge`, pakiet `mlflow` zostaje znaleziony:"
]
},
{
"cell_type": "code",
"execution_count": 9,
2021-05-31 11:55:27 +02:00
"id": "92b5da5b",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loading channels: done\n",
"# Name Version Build Channel \n",
"mlflow 0.9.0.1 py_0 conda-forge \n",
"mlflow 0.9.1 py_0 conda-forge \n",
"mlflow 1.0.0 py27_0 conda-forge \n",
"mlflow 1.0.0 py27_1 conda-forge \n",
"mlflow 1.0.0 py_2 conda-forge \n",
"mlflow 1.0.0 py_3 conda-forge \n",
"mlflow 1.1.0 py_0 conda-forge \n",
"mlflow 1.2.0 py_0 conda-forge \n",
"mlflow 1.2.0 py_1 conda-forge \n",
"mlflow 1.3.0 py36_0 conda-forge \n",
"mlflow 1.3.0 py37_0 conda-forge \n",
"mlflow 1.4.0 py36_0 conda-forge \n",
"mlflow 1.4.0 py37_0 conda-forge \n",
"mlflow 1.4.0 py38_0 conda-forge \n",
"mlflow 1.5.0 py36_0 conda-forge \n",
"mlflow 1.5.0 py36_1 conda-forge \n",
"mlflow 1.5.0 py37_0 conda-forge \n",
"mlflow 1.5.0 py37_1 conda-forge \n",
"mlflow 1.5.0 py38_0 conda-forge \n",
"mlflow 1.5.0 py38_1 conda-forge \n",
"mlflow 1.6.0 py36_0 conda-forge \n",
"mlflow 1.6.0 py37_0 conda-forge \n",
"mlflow 1.6.0 py38_0 conda-forge \n",
"mlflow 1.7.0 py36_0 conda-forge \n",
"mlflow 1.7.0 py37_0 conda-forge \n",
"mlflow 1.7.0 py38_0 conda-forge \n",
"mlflow 1.7.1 py36h9f0ad1d_0 conda-forge \n",
"mlflow 1.7.1 py37hc8dfbb8_0 conda-forge \n",
"mlflow 1.7.1 py38h32f6830_0 conda-forge \n",
"mlflow 1.7.2 py36h9f0ad1d_0 conda-forge \n",
"mlflow 1.7.2 py37hc8dfbb8_0 conda-forge \n",
"mlflow 1.7.2 py38h32f6830_0 conda-forge \n",
"mlflow 1.8.0 py36h9f0ad1d_0 conda-forge \n",
"mlflow 1.8.0 py37hc8dfbb8_0 conda-forge \n",
"mlflow 1.8.0 py38h32f6830_0 conda-forge \n",
"mlflow 1.9.1 py36h9f0ad1d_0 conda-forge \n",
"mlflow 1.9.1 py37hc8dfbb8_0 conda-forge \n",
"mlflow 1.9.1 py38h32f6830_0 conda-forge \n",
"mlflow 1.10.0 py36h9f0ad1d_0 conda-forge \n",
"mlflow 1.10.0 py37hc8dfbb8_0 conda-forge \n",
"mlflow 1.10.0 py38h32f6830_0 conda-forge \n",
"mlflow 1.11.0 py36h9f0ad1d_0 conda-forge \n",
"mlflow 1.11.0 py36h9f0ad1d_1 conda-forge \n",
"mlflow 1.11.0 py37hc8dfbb8_0 conda-forge \n",
"mlflow 1.11.0 py37hc8dfbb8_1 conda-forge \n",
"mlflow 1.11.0 py38h32f6830_0 conda-forge \n",
"mlflow 1.11.0 py38h32f6830_1 conda-forge \n",
"mlflow 1.12.0 py36h5fab9bb_0 conda-forge \n",
"mlflow 1.12.0 py37h89c1867_0 conda-forge \n",
"mlflow 1.12.0 py38h578d9bd_0 conda-forge \n",
"mlflow 1.12.1 py36h5fab9bb_0 conda-forge \n",
"mlflow 1.12.1 py37h89c1867_0 conda-forge \n",
"mlflow 1.12.1 py38h578d9bd_0 conda-forge \n",
"mlflow 1.13 py36h5fab9bb_0 conda-forge \n",
"mlflow 1.13 py37h89c1867_0 conda-forge \n",
"mlflow 1.13 py38h578d9bd_0 conda-forge \n",
"mlflow 1.13.1 py36h5fab9bb_0 conda-forge \n",
"mlflow 1.13.1 py36h5fab9bb_2 conda-forge \n",
"mlflow 1.13.1 py36hd000896_2 conda-forge \n",
"mlflow 1.13.1 py37h89c1867_0 conda-forge \n",
"mlflow 1.13.1 py37h89c1867_2 conda-forge \n",
"mlflow 1.13.1 py38h578d9bd_0 conda-forge \n",
"mlflow 1.13.1 py38h578d9bd_2 conda-forge \n",
"mlflow 1.13.1 py39hf3d152e_2 conda-forge \n",
"mlflow 1.14.0 py36h24e63a9_1 conda-forge \n",
"mlflow 1.14.0 py36h5fab9bb_0 conda-forge \n",
"mlflow 1.14.0 py36h87b8279_1 conda-forge \n",
"mlflow 1.14.0 py36hd000896_0 conda-forge \n",
"mlflow 1.14.0 py37h02d9ccd_1 conda-forge \n",
"mlflow 1.14.0 py37h89c1867_0 conda-forge \n",
"mlflow 1.14.0 py38h578d9bd_0 conda-forge \n",
"mlflow 1.14.0 py38he918c71_1 conda-forge \n",
"mlflow 1.14.0 py39ha39b057_1 conda-forge \n",
"mlflow 1.14.0 py39hf3d152e_0 conda-forge \n",
"mlflow 1.14.1 py36h24e63a9_0 conda-forge \n",
"mlflow 1.14.1 py36h87b8279_0 conda-forge \n",
"mlflow 1.14.1 py37h02d9ccd_0 conda-forge \n",
"mlflow 1.14.1 py38he918c71_0 conda-forge \n",
"mlflow 1.14.1 py39ha39b057_0 conda-forge \n",
"mlflow 1.15.0 py36h24e63a9_0 conda-forge \n",
"mlflow 1.15.0 py36h87b8279_0 conda-forge \n",
"mlflow 1.15.0 py37h02d9ccd_0 conda-forge \n",
"mlflow 1.15.0 py38he918c71_0 conda-forge \n",
"mlflow 1.15.0 py39ha39b057_0 conda-forge \n",
"mlflow 1.16.0 py36h24e63a9_0 conda-forge \n",
"mlflow 1.16.0 py36h87b8279_0 conda-forge \n",
"mlflow 1.16.0 py37h02d9ccd_0 conda-forge \n",
"mlflow 1.16.0 py38he918c71_0 conda-forge \n",
"mlflow 1.16.0 py39ha39b057_0 conda-forge \n",
"mlflow 1.17.0 py36h24e63a9_0 conda-forge \n",
"mlflow 1.17.0 py36h24e63a9_1 conda-forge \n",
"mlflow 1.17.0 py36h87b8279_0 conda-forge \n",
"mlflow 1.17.0 py36h87b8279_1 conda-forge \n",
"mlflow 1.17.0 py37h02d9ccd_0 conda-forge \n",
"mlflow 1.17.0 py37h02d9ccd_1 conda-forge \n",
"mlflow 1.17.0 py38he918c71_0 conda-forge \n",
"mlflow 1.17.0 py38he918c71_1 conda-forge \n",
"mlflow 1.17.0 py39ha39b057_0 conda-forge \n",
"mlflow 1.17.0 py39ha39b057_1 conda-forge \n",
"\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"conda search mlflow"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "7ab96758",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"\n",
"## Środowiska (Environments)\n",
"- Podstawową funkcjonalnością, którą zapewnia conda są izolowane środowiska\n",
"- Nie zapewniają one takiego stopnia izolacji co np. Docker, ale ma to swoje zalety\n",
"- Środowisko to tak naprawdę katalog zawierający zbiór bibliotek, plików wykonywalnych i innych zależności\n",
"- Środowiska mogą zawierać różne wersje zarówno modułów Python jak i bibliotek systemowych, plików wykonywalnych (w tym samego Pythona)\n",
"- Domyślne środowisko nazywa się `base`. Nie powinniśmy go modyfikować a raczej tworzyć nowe środowisko dla każdego zastosowania"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "5c57462d",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"Wyświetlanie listy środowisk:"
]
},
{
"cell_type": "code",
"execution_count": 12,
2021-05-31 11:55:27 +02:00
"id": "638002cd",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# conda environments:\n",
"#\n",
" /home/tomek/anaconda3\n",
"base * /home/tomek/miniconda3\n",
"mlflow-004410b12f95e2e00831a0ba11ee1bfdc29d6f9d /home/tomek/miniconda3/envs/mlflow-004410b12f95e2e00831a0ba11ee1bfdc29d6f9d\n",
"mlflow-503f0c7520a32f054a9d168bd099584a9439de9d /home/tomek/miniconda3/envs/mlflow-503f0c7520a32f054a9d168bd099584a9439de9d\n",
"mlflow-5987e03d4dbaa5faa1a697bb113be9b9bdc39b29 /home/tomek/miniconda3/envs/mlflow-5987e03d4dbaa5faa1a697bb113be9b9bdc39b29\n",
"\n",
"\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"conda info --envs"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "e7e40897",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"### Tworzenie środowiska\n",
"Środowisko można utworzyć i skonfigurować interaktywnie, lub z pliku `*.yml`"
]
},
{
"cell_type": "code",
"execution_count": 14,
2021-05-31 11:55:27 +02:00
"id": "0373de68",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting package metadata (current_repodata.json): done\n",
"Solving environment: done\n",
"\n",
"## Package Plan ##\n",
"\n",
" environment location: /home/tomek/miniconda3/envs/hello_env\n",
"\n",
"\n",
"\n",
"Preparing transaction: done\n",
"Verifying transaction: done\n",
"Executing transaction: done\n",
"#\n",
"# To activate this environment, use\n",
"#\n",
"# $ conda activate hello_env\n",
"#\n",
"# To deactivate an active environment, use\n",
"#\n",
"# $ conda deactivate\n",
"\n",
"\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"conda create --name hello_env -y"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "c8688ba6",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"### Aktywacja środowiska\n",
" - Żeby zmodyfikować środowisko albo zacząć z niego korzystać, musimy je aktywować.\n",
" - Aktywacja środowiska polega tak naprawdę na zmianie zmiennych środowiskowych, które mówią programom gdzie szukać ładowanych przez nie bibliotek i plików wykonywalnych, takich jak `PATH`, `PYTHON_PATH` itp.\n",
" - Po aktywowaniu środowiska w konsoli zobaczymy jego nazwę dopisaną na początku lini poleceń:"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "767f03e6",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"```\n",
"$ conda activate hello_env\n",
"(hello_env) tomek@tomek-asus:/home$ python3 --version\n",
"Python 3.8.5\n",
"```"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "245e64be",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"Domyślnie wersja pythona będzie taka sama jak systemowa.\n",
"Żeby deaktywować środowisko, używamy `conda deactivate`:"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "261f9aab",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"```\n",
"$ conda deactivate\n",
"python3 --version\n",
"Python 3.8.5\n",
"```"
]
},
{
"cell_type": "markdown",
2021-05-31 11:55:27 +02:00
"id": "980c295c",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"source": [
"### Modyfikowanie środowiska\n",
"Jeśli chcemy stworzyc środowisko z inną wersją niż systemowa:"
]
},
{
"cell_type": "code",
2023-05-17 22:30:48 +02:00
"execution_count": 1,
2021-05-31 11:55:27 +02:00
"id": "ccaadc75",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
2021-05-24 11:36:41 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting package metadata (current_repodata.json): done\n",
"Solving environment: done\n",
"\n",
"## Package Plan ##\n",
"\n",
" environment location: /home/tomek/miniconda3/envs/myenv\n",
"\n",
" added / updated specs:\n",
" - python=3.9\n",
"\n",
"\n",
"The following packages will be downloaded:\n",
"\n",
" package | build\n",
" ---------------------------|-----------------\n",
2023-05-17 22:30:48 +02:00
" ca-certificates-2023.01.10 | h06a4308_0 120 KB\n",
" libffi-3.4.2 | h6a678d5_6 136 KB\n",
" libgcc-ng-11.2.0 | h1234567_1 5.3 MB\n",
" libgomp-11.2.0 | h1234567_1 474 KB\n",
" libstdcxx-ng-11.2.0 | h1234567_1 4.7 MB\n",
" ncurses-6.4 | h6a678d5_0 914 KB\n",
" pip-23.0.1 | py39h06a4308_0 2.5 MB\n",
" python-3.9.16 | h7a1cb2a_2 25.1 MB\n",
" readline-8.2 | h5eee18b_0 357 KB\n",
" setuptools-66.0.0 | py39h06a4308_0 1.2 MB\n",
" sqlite-3.41.2 | h5eee18b_0 1.2 MB\n",
" tk-8.6.12 | h1ccaba5_0 3.0 MB\n",
" tzdata-2023c | h04d1e81_0 116 KB\n",
" wheel-0.38.4 | py39h06a4308_0 64 KB\n",