399 lines
8.6 KiB
Plaintext
399 lines
8.6 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Python- charakterystyka\n",
|
||
|
"\n",
|
||
|
"- język skryptowy ogólnego zastosowania\n",
|
||
|
"- wysokopoziomowy\n",
|
||
|
"- otwartoźródłowy\n",
|
||
|
"- działa na platformach Linux, MacOS, Windows\n",
|
||
|
"- obiektowy, ale wspiera też inne paradygmaty (np. funkcyjny)\n",
|
||
|
"- język dynamicznie typowany (x = 5 zamiast int x = 5)\n",
|
||
|
"- zarządzanie pamięcia poprzez garbage collector\n",
|
||
|
"- wcięcia (tabulacje lub spacje) zamiast nawiasów\n",
|
||
|
"- język interpretowany (zatem nie wymaga kompilacji)\n",
|
||
|
"- Obecnie używa się python w wersji 3, która nie jest kompatybilna z wersją 2. Python 2 nie jest dalej rozwijany\n",
|
||
|
"- Główną zaletą pythona jest czytelność kodu, co wynika z założenia że kod cześciej się czyta niż pisze. "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Zastosowania python\n",
|
||
|
"- najbardziej popularny język do analizy i wizualizacji danych obok R\n",
|
||
|
"- najbardziej popularny język do uczenia maszynowego, w szczególności sieci neuronowych. Posiada biblioteki TensorFlow (wraz z wbudowanym Keras), Pytorch, Jax\n",
|
||
|
"- inne zastosowania naukowe\n",
|
||
|
"- tworzenie stron internetowych (Django) oraz mikroserwisów (Flask, FastApi, Bottle, Django)\n",
|
||
|
"- skrypty, automayzacja, administracja serwerów"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Uruchamianie python\n",
|
||
|
"\n",
|
||
|
"- uruchamianie skryptu *.py wprost z wiersza poleceń\n",
|
||
|
"- uruchamianie python w trybie interaktywnym przez interpreterze python lub ipython\n",
|
||
|
"- uruchamianie skryptu + tryb interaktywny\n",
|
||
|
"- jupyter notebook, google colab\n",
|
||
|
"- IDE (np Pycharm, Microsoft Visual Studio)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Menadżery pakietów\n",
|
||
|
"- pip\n",
|
||
|
"- virtualenv\n",
|
||
|
"- conda"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"/home/anaconda3/anaconda3/bin/python\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"!which python"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### virtualenv"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!pip install virtualenv # instalacja"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!virtualenv myenv # tworzenie środowiska o nazwie myenv"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!source myenv/bin/activate # uruchamianie środowiska na linux"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!myenv\\Scripts\\activate # uruchamianie środowiska na linux na windows"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!which python"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!which pip"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!deactivate deaktywowanie środowiska"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!pip install requests # instalacja pakietów za pomocą python"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!rm -rf myenv # usuwanie środowiska"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"/bin/bash: line 1: virtualenv: command not found\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"!virtualenv --help"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"/bin/bash: line 1: virtualenv: command not found\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"!virtualenv --version"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"#### zadanie virtualenv\n",
|
||
|
"Proszę stworzyć środowisko o nazwie myscikitlearnenv, spróbować zaimportować sklearn:\n",
|
||
|
"\n",
|
||
|
"import sklearn # powinno się nie udać\n",
|
||
|
"\n",
|
||
|
"Następnie zainstalować w nim scikit-learn i ponownie spróbować zaimportować sklearn (tym razem powinno się udać)\n",
|
||
|
"\n",
|
||
|
"Następnie deaktywować środowisko i usunąć je."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## conda (anaconda, miniconda, miniforge)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# najpierw - instalacja anconda"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "raw",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"! tail -n30 ~/.bashrc # conda uruchamia się w ~/.bashrc"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!conda create --name myenv # tworzenie nowego środowiska"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!conda create --name myenv python=3.9 # tworzenie nowego środowiska dla python w wersji 3.9"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!conda activate myenv # aktywowanie środowiska"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!which python"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!conda deactivate # deaktywowanie środowiska"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!conda env list # wylistowanie dostępnych środowisk"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!conda install requests # instalacja pakietu za pomocą conda"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!conda install nodejs # instalacja nodejs (coś zupełnie poza środowiskiem pythona)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!pip install requests # instalacja pakietu za pomocą pip\n",
|
||
|
"!pip install scikit-learn # instalacja pakietu za pomocą pip"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!conda env export > environment.yml # eksport środowiska"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!conda env create -f environment.yml # import środowiska"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!conda list # wylistowanie zainstalowanych pakietów"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!conda --help"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"!conda --version"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"!conda remove --name nazwa_srodowiska --all # usuwanie środowiska- albo wystarczy wprost usunąć pliki środowiska\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"#### zadanie conda\n",
|
||
|
"1. Proszę zrobić te same kroki jak w poprzednim zadaniu\n",
|
||
|
"2. Proszę zrobić to co w punkcie 1. tylko, że przed usunięciem środowiska zapisać je do environment.yml, a po usunięciu odtworzyć"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3 (ipykernel)",
|
||
|
"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.11.7"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 4
|
||
|
}
|