[EN/PL] Introduction to Python, installation of the environment / Wstęp do Pythona, instalacja środowiska

in #polish2 years ago



[ENGLISH] - Polski dostępny niżej

Let's get straight to the point without any long introductions!

Environment

  1. Due to the fact that many subsequent tutorials will cover the topic of Python, let's start with its installation and some environment in which we will be coding. I assume that if you are reading this tutorial, your only editor is called Notepad, and while you can do something with Notepad++, something bigger will come in handy. It may seem unimportant, but only over time will you notice how much the environment you use can make your work easier or harder. In my opinion, the best free option that I can recommend is Visual Studio Code, which you can download here:
    https://code.visualstudio.com/

Python

  1. Over time, you will figure out which version you need. At the beginning, don't download a version that is too new, as tutorials you watch online may be based on an older version, and not everything will work as intended. For the purposes of this tutorial, I choose version 3.9. We can download Python from the website: https://www.python.org/.

  2. Run the downloaded installer as an administrator.

  3. Select "Add Python 3.9 to PATH".

  4. Choose the location for installation that interests us. For ease of use and installation of other versions in the future, we choose a personalized path by clicking "Customize installation" and then "Next".

  5. In "Customize install location", we choose the disk, then create a "Python" directory and within it, according to the version, "Python39", and click "Install". This way, in the future, we will install subsequent versions in the "Python" directory and keep it organized. It is possible to do it using the default installation, but in my opinion, this method is more accessible. Finally, click "Close".

  6. Open the PowerShell console and type:

python --version



If you did everything correctly, the installed version number will be displayed.

  1. We will make it easier to call Python by adding a shortcut to the console, and here we will use the editor mentioned earlier. While remaining in the console, we type:
code $profile



This should create a file named Microsoft.PowerShell_profile.ps1 located in C:\Users\YourUsername\Documents\WindowsPowerShell\ or in a different documents location if the default was changed.

  1. We create an alias at the end of the file using the path chosen for Python installation. In my case, it will be the following line:
Set-Alias py "C:\Python\Python39\python.exe"
  1. We save the changes and restart the console. Now we will use py instead of python to run Python scripts. You can check this by typing in the console:
py --version

You have installed Python and an editor. In the following tutorials, you will learn the basics of using this language in practice. Don't worry, you won't see any "Hello world!" type tutorials from me. Only meat! Programs that can actually be useful.

See you in the next tutorial!

[POLISH]

Lecimy z tematem od razu bez przydługich wstępów!

Środowisko

  1. Z racji tego, że w wielu kolejnych tutorialach będzie poruszany temat Pythona zabierzmy się za jego instalację oraz jakieś środowisko w którym będziemy kodować. Zakładam, że jeśli zaglądasz do tego tutorialu to Twój jedyny edytor nazywa się notatnik i o ile w notepad++ da się coś zrobić to przyda się coś większego. Wydaje się być mało ważne lecz dopiero z czasem zauważysz jak ułatwia lub utrudnia Ci pracę dane środowisko. Moim zdaniem najlepszy z darmowych jaki można polecić to oczywiście Visual Studio Code, który pobierzesz tutaj:
    https://code.visualstudio.com/

Python

  1. Z czasem sam dojdziesz do tego, która wersja Ci jest potrzebna. Na początek nie pobieraj zbyt nowej gdyż obejrzane tutoriale w sieci mogą bazować na starszej wersji i nie wszystko będzie chciało działać. Na potrzeby tutorialu wybieram wersję 3.9 . Pythona pobieramy ze strony: https://www.python.org/

  2. Uruchom pobrany instalator jako administrator

  3. Zaznaczamy Add Python 3.9 to PATH

  4. Wybieramy interesującą nas lokalizację instalacji, dla ułatwienia i instalowania innych wersji w przyszłości wybieramy ścieżkę spersonalizowaną klikając "Customize installation" i następnie "Next"

  5. W "Customize install location" wybieramy dysk, następnie tworzyny katalog "Python" a w nim zgodnie z wersją "Python39" i klikamy "Install". Dzięki temu w przyszłości w katalogu "Python" będziemy instalować kolejne wersje i trzymać porządek. Można to zrobić korzystając z domyślnej instalacji jednak ta moim zdaniem jest bardziej dostępna. Na koniec klikamy "Close".

  6. Otwieramy konsolę PowerShell i wpisujemy

python --version



Jeśli wszystko zrobiliśmy jak należy wyświetli się numer zainstalowanej właśnie wersji.

  1. Ułatwimy sobie wywoływanie pythona dodając skrót do konsoli i tutaj skorzystamy z edytora o którym była mowa wcześniej. Pozostając w konsoli wpisujemy:
code $profile



powinno to utworzyć plik Microsoft.PowerShell_profile.ps1 znajdujący się w lokalizacji C:\Users\TwojaNazwaUsera\Documents\WindowsPowerShell\ lub innej lokalizacji dokumentów jeśli domyślna została zmieniona.

  1. Tworzymy alias na końcu pliku używając ścieżki wybranej do instalacji Pythona, w moim przypadku będzie to następująca linijka:
Set-Alias py "C:\Python\Python39\python.exe"
  1. Zapisujemy i uruchamiamy ponownie konsolę. Teraz do uruchomiania skryptów Pythona będziemy używać py zamiast python . możesz to sprawdzić wpisując w konsoli:
py --version

Masz już zainstalowanego Pythona i edytor. Z następnych tutoriali nauczysz się podstaw wykorzystania tego języka w praktyce. Nie martw się u mnie nie uświadczysz tutoriali typu "Hello world!". Tylko mięso! Programy, które faktycznie mogą się do czegoś przydać.

Do następnego tutorialu!