├── .env ├── .env_linux ├── .gitattributes ├── .gitignore ├── README.md └── README_Portugues.md /.env: -------------------------------------------------------------------------------- 1 | PYTHONPATH=%PYTHONPATH%;"C:\\Users\\JNC\\Anaconda3\\envs\\test_01_proj\\python.exe" 2 | PATH=%PATH%;C:\\Users\\JNC\\Anaconda3\\envs\\test_01_proj\\" 3 | -------------------------------------------------------------------------------- /.env_linux: -------------------------------------------------------------------------------- 1 | PYTHONPATH="$PYTHONPATH:/home/joao/anaconda3/envs/test_01_proj/bin/python" 2 | PATH="$PATH:/home/joao/anaconda3/envs/test_01_proj/bin/" 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows thumbnail cache files 2 | Thumbs.db 3 | ehthumbs.db 4 | ehthumbs_vista.db 5 | 6 | # Folder config file 7 | Desktop.ini 8 | 9 | # Recycle Bin used on file shares 10 | $RECYCLE.BIN/ 11 | 12 | # Windows Installer files 13 | *.cab 14 | *.msi 15 | *.msm 16 | *.msp 17 | 18 | # Windows shortcuts 19 | *.lnk 20 | 21 | # ========================= 22 | # Operating System Files 23 | # ========================= 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # How to learn modern Python 2 | **A guide to the adventurer**
3 |
4 | [Click para versão em Português/Portuguese version](./README_Portugues.md)
5 |
6 | First to learn modern Python you have to choose an operating system. The Python is the same in all of them but some settings and the libs used by your future programs may be supported in one OS and not in the other OS. In this guide I focus on the development in Linux and Windows, but the info can also be useful for other operating systems.
7 | 8 | * In this context we start by installing Ubuntu Linux, as a stand alone machine or as a virtual machine. If you plan to use Windows jump this step.
9 | [Ubuntu](https://www.ubuntu.com/download/desktop)
10 | 11 | * Install the Python distribution Anaconda, with Python version 3.7 or greater.
12 | [Anaconda Distribution](https://www.anaconda.com/distribution/) 13 | 14 | * Install an IDE (Integrated Development Environment) and an editor, I choose Visual Studio Code to develop but I also like to have Sublime Text to open a file quickly. Both work on Linux, Windows and Mac, and both are fast.
15 | [Visual Studio Code](https://code.visualstudio.com/)
16 | [Sublime Text](https://www.sublimetext.com/)
17 | 18 | * In youtube search and see some videos on how to use Visual Studio Code and explore the menus and buttons. 19 | 20 | * In Visual Studio Code, install the following Plugins directly in the IDE (Square button on the left):
21 | [Python ... syntax highlighting, code completion and debugging](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
22 | [Anaconda Extension Pack ... ](https://marketplace.visualstudio.com/items?itemName=ms-python.anaconda-extension-pack)
23 | [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner)
24 | [Code Spell Checker... comments and code](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker)
25 | [Markdown All in One ... markdown syntax highlighting and preview](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one)
26 | [Better Comments ... TODO list's in code comments and more](https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments)
27 | 28 | * Create a new directory for the project ex: proj/test_01_proj, create a Python file with extension ".py", ex: test_01.py and write "print("Hello World!")". 29 | 30 | * Create and setup the virtual environment and the packages in Anaconda for the project on Linux or Windows. This will means that the packages you install will be installed specifically for your project virtual environment an not for the base installation.
31 | 32 | See the conda version: 33 | 34 | ``` 35 | $ conda -V 36 | ``` 37 | 38 | Update conda 39 | 40 | ``` 41 | $ conda update conda 42 | ``` 43 | 44 | Create a virtual environment for your project (substitute yourenvname by the name of the environment ex: test_01_proj and the x.x by 3.7 the version of Python in the future environment). 45 | 46 | ``` 47 | $ conda create -n yourenvname python=x.x anaconda 48 | ex: $ conda create -n test_01_proj python=3.7 anaconda 49 | ``` 50 | 51 | See the environments that were created. 52 | 53 | ``` 54 | $ conda info -e 55 | ``` 56 | 57 | To activate the environment 58 | 59 | ``` 60 | $ source activate yourenvname 61 | ex: $ source activate test_01_proj 62 | ``` 63 | 64 | or 65 | 66 | ``` 67 | $ conda activate test_01_proj 68 | ``` 69 | 70 | To desactivate an active environment 71 | 72 | ``` 73 | $ source activate yourenvname 74 | ex: $ source desactivate 75 | ``` 76 | 77 | or 78 | 79 | ``` 80 | $ conda deactivate 81 | ``` 82 | 83 | Install additional Python packages to a virtual environment. 84 | 85 | ``` 86 | $ conda install -n yourenvname [package] 87 | ex: $ conda install -n test_01_proj svgwrite 88 | ``` 89 | 90 | Delete a no longer needed virtual environment
91 | 92 | ``` 93 | $ conda remove -n yourenvname -all 94 | ex: $ conda remove -n test_01_proj -all 95 | ``` 96 | 97 | * In your project select the correct interpreter.
98 | ctrl + shift + p then write "Python select interpreter" command and choose the virtual environment test01_proj that you created from the drop-down selection. 99 | 100 | * Install in Python PyLint and CTags on the virtual environment. 101 | 102 | ``` 103 | $ conda install -n test_01_proj -c conda-forge pylint 104 | $ conda install -n test_01_proj -c conda-forge ctags 105 | ``` 106 | 107 | * In Visual Studio Code, copy one ".env" file from inside GitHub to the directory of the project, it will initialize the environment variables, adjust the paths to your virtual environment (user). The following is necessary for now because VSCode doesn't activate automatically the virtual environment when debugging.
108 | For Windows copy the file ".env" in github to your project directory.
109 | For Linux copy the file ".env_linux" in github to your project directory and rename it ".env". 110 | 111 | * Now for Python it self. View two times the following 45 minutes video that explains the main parts of the Python language. View it from the beginning to the end, even if you don’t understand all of what is explained. In the next step the Python language will be explained in more detail. Ignore the part of the video that teach how to install Python and the IDE PyCharm.
112 | [Python Programming video by Derek Banas](https://www.youtube.com/watch?v=N4mEzFDjqtA) 113 | 114 | * Follow the free official tutorial of Python and study it well.
115 | [The Python Tutorial](https://docs.python.org/3/tutorial/) 116 | 117 | * Read the following book from cover to cover, don't look at the title see the table of contents it's a really good Python all around book.
118 | [Effective Computation in Physics: Field Guide to Research with Python 1st Ed. by Anthony Scopatz, Kathryn D. Huff](https://www.amazon.com/Effective-Computation-Physics-Research-Python-ebook/dp/B010ORQ8DG/ref=sr_1_10) 119 | 120 | * You only really understand a programming language and programming generally, after you have sean many projects written in the language. So study the following book full of projects and the respective code.
121 | [Python Playground: Geeky Projects for the Curious Programmer 1st Ed by Mahesh Venkitachalam](https://www.amazon.com/Python-Playground-Projects-Curious-Programmer-ebook/dp/B017AH8H7I/ref=pd_sim_351_6/175-5456264-3791003) 122 | 123 | * For all your Python development your main source of documentation will always be
124 | [Python 3.x documentation](https://docs.python.org/3/) 125 | 126 | * **Jupyter Notebooks**
127 | [1. Introduction - Jupyter Tutorial](https://www.youtube.com/watch?v=Rc4JQWowG5I&list=PL1m-6MPBNAZfF-El7BzqaOrCrTBRgH1Nk&index=1)
128 | [2. Markdown & LaTeX - Jupyter Tutorial](https://www.youtube.com/watch?v=-F4WS8o-G2A&list=PL1m-6MPBNAZfF-El7BzqaOrCrTBRgH1Nk&index=4)
129 | [3. Python 3 - Jupyter Tutorial](https://www.youtube.com/watch?v=1I2Bz0qbMsc&list=PL1m-6MPBNAZfF-El7BzqaOrCrTBRgH1Nk&index=5)
130 | [4. Numpy - Jupyter Tutorial](https://www.youtube.com/watch?v=ZABbRR0tfuc&list=PL1m-6MPBNAZfF-El7BzqaOrCrTBRgH1Nk&index=6) 131 | 132 | 133 | If you do all this steps you will have a fair knowledge of Python and can start doing some cool projects in Python.
134 | 135 | Have fun!
136 | 137 | Best regards,
138 | Joao Nuno Carvalho 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /README_Portugues.md: -------------------------------------------------------------------------------- 1 | # Como aprender Python moderno 2 | **Um guia para o aventureiro**
3 |
4 | [Click for the English version/Versão Inglesa](./README.md)
5 |
6 | Em primeiro lugar para aprender Python moderno, temos de escolher o sistema operativo em que vamos desenvolver. A linguagem Python é a mesma em todos os sistemas operativos mas algumas configurações e as bibliotecas usadas pelos nossos futuros programas, podem existir para um S.O. e não existir para outro S.O. . Este guia foca no desenvolvimento em Linux e Windows, mas a informação poderá ser útil para outros sistemas operativos.
7 | 8 | * Neste contexto começamos por instalar a distribuição de Linux Ubuntu, como sistema operativo principal do PC ou como uma máquina virtual. Se tenciona usar Windows pode saltar este passo.
9 | [Ubuntu](https://www.ubuntu.com/download/desktop)
10 | 11 | * Instale a distribuição de Python Anaconda, com Python na versão maior ou igual a 3.7 .
12 | [Anaconda Distribution](https://www.anaconda.com/distribution/) 13 | 14 | * Instale um IDE (Integrated Development Environment), ambiente de desenvolvimento integrado ou um editor de texto. Eu para desenvolver escolhi o Visual Studio Code, mas também gosto de ter instalado o editor Sublime Text para abrir ficheiros de forma rápida. Ambos funcionam em Linux, Windows e Mac, e ambos são rápidos e leves em termos de recursos.
15 | [Visual Studio Code](https://code.visualstudio.com/)
16 | [Sublime Text](https://www.sublimetext.com/)
17 | 18 | * Procure e veja no youtube, alguns vídeos sobre o Visual Studio Code e explore os menus e os botões. 19 | 20 | * Instale directamente no IDE do Visual Studio Code, os seguintes Plugins (Botão quadrado no lado esquerdo):
21 | [Python ... mostra a sintaxe em cores diferentes, completa o código e debugging](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
22 | [Anaconda Extension Pack ... ](https://marketplace.visualstudio.com/items?itemName=ms-python.anaconda-extension-pack)
23 | [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner)
24 | [Code Spell Checker... comentários e código](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker)
25 | [Markdown All in One ... markdown com sintaxe em cores diferentes e pré-visualização](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one)
26 | [Better Comments ... Listas TODO nos comentários do código e outras extras](https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments)
27 | 28 | * Crie uma directoria para o projecto ex: proj/test_01_proj, crie um ficheiro de Python com a extensão ".py", ex: test_01.py e escreva "print("Hello World!")". 29 | 30 | * Criação e configuração do virtual environment (ambiente virtual) e dos packages (pacotes) em Anaconda para o projecto no Linux ou Windows. Isto significa que os pacotes que serão instalados serão somente instalados no ambiente virtual de Python usado no projecto e que não irão ser instalados na instalação base do Python. 31 | 32 | Ver a versão do conda que está instalada: 33 | 34 | ``` 35 | $ conda -V 36 | ``` 37 | 38 | Actualizar a versão do conda 39 | 40 | ``` 41 | $ conda update conda 42 | ``` 43 | 44 | Crie um virtual environment (ambiente virtual) para o seu projecto (substitua yourenvname pelo nome do ambiente virtual ex: test_01_proj e o x.x por 3.7 , que será a versão do Python do seu futuro ambiente virtual). 45 | 46 | ``` 47 | $ conda create -n yourenvname python=x.x anaconda 48 | ex: $ conda create -n test_01_proj python=3.7 anaconda 49 | ``` 50 | 51 | Veja o ambiente que foi criado. 52 | 53 | ``` 54 | $ conda info -e 55 | ``` 56 | 57 | Active o ambiente 58 | 59 | ``` 60 | $ source activate yourenvname. 61 | ex: $ source activate test_01_proj 62 | ``` 63 | 64 | or 65 | 66 | ``` 67 | $ conda activate test_01_proj 68 | ``` 69 | 70 | 71 | Para desactivar o ambiente. 72 | 73 | ``` 74 | $ source activate yourenvname 75 | ex: $ source desactivate 76 | ``` 77 | 78 | or 79 | 80 | ``` 81 | $ conda deactivate 82 | ``` 83 | 84 | Para instalar pacotes adicionais no seu ambiente virtual. 85 | 86 | ``` 87 | $ conda install -n yourenvname [package] 88 | ex: $ conda install -n test_01_proj svgwrite 89 | ``` 90 | 91 | Para apagar um ambiente virtual que já não seja necessário. 92 | 93 | ``` 94 | $ conda remove -n yourenvname -all 95 | ex: $ conda remove -n test_01_proj -all 96 | ``` 97 | 98 | * Dentro do Visual Studio Code, com o seu projecto aberto, seleccione o interpretador de Python usar neste projecto.
99 | ctrl + shift + p depois escreva o comando "Python select interpreter" e escolha o virtual environment test01_proj que acabou de criar, da caixa de selecção drop-down. 100 | 101 | * Instale os pacotes de Python, PyLint e CTags no ambiente virtual, eles serão usados para detectar os erros quando grava e para navegar entre os simbolos do código. 102 | 103 | ``` 104 | $ conda install -n test_01_proj -c conda-forge pylint 105 | $ conda install -n test_01_proj -c conda-forge ctags 106 | ``` 107 | 108 | * No Visual Studio Code, copie o ficheiro ".env" que está dentro da directoria do projecto do GitHub. Este ficheiro vai inicializar as variáveis de ambiente na linha de comandos (shell), tem de ajustar os paths tendo em conta o seu user e o nome do seu ambiente virtual. É necessário fazer este passo pois o VSCode não activa automaticamente o ambiente virtual quando faz o debug.
109 | Para o Windows copie o ficheiro ".env" do github para a directoria do projecto.
110 | Para o Linux copie o ficheiro ".env_linux" do github para a directoria do projecto e renomei-o de ".env". 111 | 112 | * Agora em termos da linguagem Python propriamente dita. Vejam duas vezes o seguinte vídeo de 45 minutos a explicar a linguagem Python. Vejam do início até ao fim mesmo que não consigam perceber tudo o que é explicado. No passo seguinte a linguagem Python vai ser explicada mais com mais detalhe. Ignorem a parte da instalação do Python e do IDE PyCharm.
113 | [Python Programming video by Derek Banas](https://www.youtube.com/watch?v=N4mEzFDjqtA) 114 | 115 | * Leia atentamente o tutorial oficial do Python que é gratuito e é muito bom. Estude-o bem que vale a pena!
116 | [The Python Tutorial](https://docs.python.org/3/tutorial/) 117 | 118 | * Leia o livro seguinte do início ao fim, não leve à letra o título do livro, veja o índex do livro. Este livro é um livro muito bom e muito abrangente que cobre várias áreas do desenvolvimento em Python.
119 | [Effective Computation in Physics: Field Guide to Research with Python 1st Ed. by Anthony Scopatz, Kathryn D. Huff](https://www.amazon.com/Effective-Computation-Physics-Research-Python-ebook/dp/B010ORQ8DG/ref=sr_1_10) 120 | 121 | * Uma pessoa só percebe verdadeiramente uma linguagem de programação e a arte de programar, depois de ter visto e estudado vários projectos escritos na linguagem. Por isso peço-vos que estudem o livro seguinte que está cheio de pequenos projectos em várias áreas com o respectivo código em Python.
122 | [Python Playground: Geeky Projects for the Curious Programmer 1st Ed by Mahesh Venkitachalam](https://www.amazon.com/Python-Playground-Projects-Curious-Programmer-ebook/dp/B017AH8H7I/ref=pd_sim_351_6/175-5456264-3791003) 123 | 124 | * Para todo o desenvolvimento em Python a fonte principal de documentação será sempre o link seguinte para a documentação oficial
125 | [Python 3.x documentation](https://docs.python.org/3/) 126 | 127 | * **Jupyter Notebooks**
128 | [1. Introduction - Jupyter Tutorial](https://www.youtube.com/watch?v=Rc4JQWowG5I&list=PL1m-6MPBNAZfF-El7BzqaOrCrTBRgH1Nk&index=1)
129 | [2. Markdown & LaTeX - Jupyter Tutorial](https://www.youtube.com/watch?v=-F4WS8o-G2A&list=PL1m-6MPBNAZfF-El7BzqaOrCrTBRgH1Nk&index=4)
130 | [3. Python 3 - Jupyter Tutorial](https://www.youtube.com/watch?v=1I2Bz0qbMsc&list=PL1m-6MPBNAZfF-El7BzqaOrCrTBRgH1Nk&index=5)
131 | [4. Numpy - Jupyter Tutorial](https://www.youtube.com/watch?v=ZABbRR0tfuc&list=PL1m-6MPBNAZfF-El7BzqaOrCrTBRgH1Nk&index=6) 132 | 133 | 134 | Se fizer todos os passos anteriores, irá possuir um conhecimento bastante abrangente de Python e com isso poderá começar a fazer projectos muito interessantes e divertidos em Python.
135 | 136 | Espero que se divirta bastante com o Python!
137 | 138 | Cumprimentos,
139 | Joao Nuno Carvalho 140 | 141 | 142 | 143 | 144 | --------------------------------------------------------------------------------