This post introduces to some aspects of Python development.
Python Programming Language
Python applications are developed using Python programming language.
You can find more information about Python programming language on this post.
Integrated Development Environments (IDEs) for Python
It is not mandatory to use an IDE to develop Python as there is a command-based tool. However, it may be more productive for most users to use a proper Integrated Development Environment (IDE).
As of 2023, the most popular IDEs for Python could be PyCharm and Visual Studio Code. Both of them have a free and open-source (FOSS) versions.
Official Python IDE is Python IDLE.
PyCharm is a dedicated Python IDE developed by Czech company JetBrains that offers extended functionalities than Python IDLE. There are two versions: an open source Community Edition, and a paid Professional edition.
You can find more information about PyCharm on this post.
Visual Studio is an IDE developed by American company Microsoft. You can get more information about compatibility with Python on this external link.
Visual Studio Code, also known as VS Code, is a general source code editor developed by Microsoft. You need to install an extension for Python in order to work for this programming language.
Take note that while VS Code source code is FOSS under an MIT license, Microsoft installer is not and the bundle includes telemetry tracking. If you want to get a pre-built FOSS installer, have a look at VSCodium.
There are Python extensions for Eclipse IDE, as for example, PyDev. Check these posts about how to install and configure Python on Eclipse on Windows and Ubuntu.
Jupyter Notebook is an interesting web application for development of Python and other programming languages.
Google Colab is a cloud service for Jupyter Notebook. You can visit it on this external link.
Kaggle is a web app to use AI through Python.
Python software project building
A common way to build a Python project is opening a terminal, going to the folder where the project is located and typing:
python3 -m venv .venv
source .venv/bin/activate
pip install -e .
The first two commands set a virtual environment to install the environment. This is not mandatory, but it is a cleaner approach that avoids dependency conflicts.
python3 -m venv .venv uses the Python module venv to create a virtual environment in folder .venv, that is the standard folder to build a virtual environment.
source .venv/bin/activate activates the virtual environment just created.
pip install -e . installs the program located in the current folder to the current virtual environment.
The parameter -e sets editable mode, where the programs are linked rather than copy. This avoids having to reinstall after files have been modified.
This assumes that within the project folder there is a pyproject.toml or setup.py file.
The pyproject.toml file could have this content.
[project]
name = "Project Name"
version = "0.0.0"
description = "Project description"
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
[tool.setuptools.packages.find]
where = ["src"]
[project.scripts]
projectscriptname = "projectname.packagename:methodname"
This example uses the setuptools Python package tools, but there are others available. You can read this post about Python backd tools.
The “where” value within [tool.setuptools.packages.find] informs where the packages are located. In this example, source code package is located in the popular folder src.
The project.scripts allows that when you type projectscriptname within the terminal (and the virtual environment is activated, if you used it) the program on the right is run. It could be projectname.main:main.
One drawback of using setuptools is that it adds some artifacts like the projectname.egg-info folder and __pycache__ folders to your source code folder. When git is used, these artifact folders should be added to .gitignore. You can avoid having these artifacts by using alternatives.
Package management
A folder within a Python project becomes a package when the file __init__.py is added to it.
You can add the importable methods to the __init__.py and then the method implementation in a different file, such as core.py:
# File "__init.py__" in folder "package"
# Looks for file "core" in the same package directory
from .core import method
# Controls what gets imported when all methods from a package are loaded using wildcard *
__all__ = ["method"]
Then you can import it in the project in this way:
from package import method
method()
Learning Python
How do I start learning Python?
The official Python tutorial can be found on this external link. As it is quite old, there are other much user-friendlier.
Recommended online tutorials:
- Learn Python by Datacamp
- Python for Beginners by Microsoft Learn
- Python tutorial by W3School
- LearnPython.org
There are many other webs and books to teach you how to learn Python. Just search for it using your favourite search engine.
Getting Help on Python
Groups to get help about Python.
Reddit group r/learnpython
Python Discord
Python Discord is a community of Python developers that communicate through Discord.
LinkedIn group “Python Developers Community”
StackOverflow
Link to questions about Python on Stack Overflow
Python Resources
Official Python Documentation
PEP 8
PEP 8 is the official style guide for Python code.
You can read PEP 8 from this external link.
The Zen of Python
You can read “The Zen of Python” by opening Python session and typing “import this”.
Eric Matthes’ Python Crash Course Resources
Eric H. Matthes is the author of “Python Crash Course”.
GitHub repository for Python Crash Course 3rd Edition Resources