Skip to content

Latest commit

 

History

History
132 lines (93 loc) · 6.35 KB

File metadata and controls

132 lines (93 loc) · 6.35 KB

Python for Everyone

This is just a set of contents in order to provide you some examples and simple explanations about python syntaxis and useful capabilities you could use to develop your academic (and non-academic) projects.

Table of Contents:

Notebooks Distribution

To make it simple, Jupyter Notebooks are used to explain the concepts, so it is a good idea to get familiar with notebook usage.

As follows, it is presented the recommended order to explore the notebooks:

  1. Conditionals - On Construction
  2. Loops - On Construction
  3. Functions
  4. Tuples
  5. Lists - On Construction
  6. Strings
  7. Dictionaties - On Construction
  8. Files - On Construction
  9. Exceptions - On Construction

You can check any notebook at any time you need, the recommendation is not a mandatory path.

How to Setup Python on your Machine

The courses are built around python, so it is pretty important to have python installed and tunned in your machine.

Installing Python

Windows

To install Python on your Windows machine, follow these steps:

  1. Visit the official Python website at python.org.
  2. Click on the Downloads tab. Scroll down to the Python Releases for Windows section, and choose the version of Python you want to install. It is recommended to select the latest stable version. However, these courses are built using Python 3.11.0.
  3. Click on the download link for the Windows installer corresponding to your system architecture (32-bit or 64-bit probably). Once the installer is downloaded, double-click on it to start the installation process.
  4. In the installer, select the option to Add Python to PATH and click on Install Now. If you forget this step, Windows will not execute python when you need it.
  5. The installer will now install Python on your machine. This may take a few minutes.
  6. Once the installation is complete, you can verify that Python is installed by opening the command prompt, I recommend to use PowerShell, and typing python --version. You should see the version number of Python printed on the screen.

Congratulations! You have successfully installed Python on your Windows machine.

UNIX Systems

For UNIX Systems, as Linux and MacOS, python is installed by default.


Creating Virtual Environments

There are different tools to create virtual environments, but I use PyEnv, it is simple and lets to create virtual environments on different python versions, it is amazing. You could check a good tutorial https://realpython.com/intro-to-pyenv/.

  1. Open a Terminal linux or PowerShell window.

  2. Install PyEnv by running the following command:

curl https://pyenv.run | bash

This will download and install PyEnv on your system.

  1. Add PyEnv to your system's PATH by running the following command:
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc

This will ensure that PyEnv is available in Terminal linux or PowerShell windows.

  1. Restart your Terminal or PowerShell window to apply the changes to your PATH.

  2. Install Python 3.11.0 using PyEnv by running the following command:

pyenv install 3.11.0

This will download and install Python 3.11.0 on your environments, but this installation does not affect the python version you have globally in your operative system. In this way, you could install a lot of different python version in your machine without any problem.

  1. Create a virtual environment using Python 3.11.0 by running the following command:
pyenv virtualenv 3.11.0 <env_name>

Replace <env_name> with the desired name for your virtual environment.

  1. Activate the virtual environment by running the following command:
pyenv activate <env_name>

Replace <env_name> with the name of your virtual environment.

Congratulations! You have successfully created a virtual environment using PyEnv and installed Python 3.11.0 on your machine.


"Pimp" your VS Code (Optional)

There are a lot of different Integrated Development Environment (IDE), however I recommend to use VS Code. This one is FOSS, with a lot of updates, extensions, support different programming languages, simple to use and setup.

To install extensions in VS Code, follow these steps:

  1. Open VS Code. Click on the Extensions icon on the left sidebar, or press Ctrl+Shift+X (Cmd+Shift+X on macOS) to open the Extensions view.
  2. In the search bar at the top of the Extensions view, type the name of the extension you want to install.
  3. From the search results, click on the extension you want to install. On the extension page, click on the Install button. Wait for the installation to complete. You will see a notification once the installation is finished.
  4. After the installation, you may need to reload VS Code for the extension to take effect. You can do this by clicking on the Reload button in the notification, or by restarting VS Code.
  5. That's it! The extension is now installed and ready to use in VS Code. You can manage your installed extensions by clicking on the Extensions icon and accessing the Installed tab.

Also, I strongly recommend you to install next extensions:

  • Python: Code colors, syntax validations
  • Pylint: Verification of code quality
  • Jupyter: Notebooks into IDE
  • BlackFormatter: Format python code
  • isort [maybe]: Organize imports order.
  • Docker: Containers management.
  • DevContainers: See containers content.
  • GitLens: Handle git commits, changes, among others.
  • TODO Tree: Task to do in the code.
  • LaTeX: Write and build LaTeX documents.
  • Postman: Call web APIs.