Starting Python Development on Windows

Posted in programming with tags python windows -

Summary

Notes on starting Python development with Windows.

Installing Python on Windows

First, download the latest version of Python from the official Website. Choose the Windows x86-64 executable installer for the latest version of Python 3, unless you know that you need a different option.

Run the installer, and select the option to Add Python to PATH, so that you do not need to type the full path for Python commands. If prompted, choose the option to remove the path length limitation from Windows.

A standard Python installation provides you with:

  • The Python runtime
  • An interactive shell (use the menu icon, or type python in a command prompt window)
  • A basic IDE, called IDLE
  • A large standard library, along with documentation
  • An extensive tutorial, to help you get started

IDLE is intended as a basic and portable development environment that lets new programmers start without having to install a separate editor for their code. For a much better experience, install a text editor or IDE that supports Python.

The tutorial that is supplied with Python can walk you through the basics. The documentation for the standard library does provide simple examples for many features, but it is specifically designed as a reference, rather than for learning. The last section of this article gives you links to courses and books that you may find more helpful when starting with Python.

Choosing a Code Editor or IDE

My preferred text editor is currently Visual Studio Code. This tutorial shows you the features that Visual Studio Code has for Python development, including code quality checks, and support for debugging. You may prefer Atom, which is a high-quality and customisable editor that has plugins for Python, or Notepad++, which will be more suitable for older computers with limited resources. All of these editors are free.

If you would like to use a full IDE, consider the Wing IDE, which is proprietary, or using the free Eclipse IDE with the PyDev extension. Current versions of Microsoft Visual Studio also include support for Python.

Essential Tools

There are a number of de-facto standard utilities and libraries for Python software development, but a few tools are so fundamental that you should install them even before you begin to write Python code.

pipenv for Virtual Environments

Install pipenv to manage your Python projects. It ensures that each of your Python projects use a separate set of packages, and provides other features to help you maintain your work, such as checking the code and warning you about security issues in libraries.

In a command prompt window enter the following command:

pip install pipenv

The pipenv tool uses the pip and virtual environment facilities that are included with Python itself, so it is fully compatible with other Python utilities, whilst being much easier to use than other tools. The Python packaging documentation now officially recommends pipenv.

The Python Guide tutorial shows you how to work with pipenv.

Git for Version Control

If you do not already use version control, you should also install Git on your system. Git is now effectively the standard version control tool for developers.

Version control is obviously vital for collaborating with other programmers. It also enables you to efficiently copy your application to other systems for testing, deployment and backup.

If Git is installed, Atom and Visual Studio Code provide you with access to information and features from Git directly in their user interfaces. If you use Visual Studio Code, you should also consider installing the Git Lens extension, which enhances the integration with Git.

A number of other tools are commonly used in Python development. You should probably learn these as you need them.

If you install the Python extension, Visual Studio Code will offer to use Pylint and autopep8 to check and format your code.

Web Applications

For very simple Websites and services, use Flask. The Flask framework provides the basic package of features that you need for a small Web application.

Use either Django or Pyramid for larger Websites. Django provides a set of custom tools and libraries that closely integrate together. Pyramid offers a modular framework for integrating third-party Python libraries together when developing custom Web applications.

Python Web frameworks follow the WSGI standard, which provides consistent interfaces between individual components, and between the components and the host Web server. Any server that supports WSGI can host your Python applications. Cloud services such as Google App Engine, Heroku, Python Anywhere and Red Hat OpenShift provide low-maintenance hosting for Python Web applications.

Full Stack Python provides a comprehensive guide to building Web applications with Python.

Web Clients

Use the requests library for your Web client software, such as downloading files or working with APIs. The HTTP support in the Python standard library is for low-level code.

If you need to get information from Websites that do not provide an API, use Scrapy. You can then extract content from the pages with the Beautiful Soup library.

Accessing Databases

The simplest answer: you do not need to install anything or setup a service to create a SQL database for a new Python application, because the Python standard library includes a version of SQLite.

To access a SQL database service such as PostgreSQL, MySQL, or Oracle you will need to install the client software for that product, along with a separate Python adapter.

Connecting to Microsoft SQL Server: Microsoft recommend that you use the ODBC adapter for SQL Server.

The Django Web framework includes an Object-Relational Mapper (ORM). For other applications, use SQLAlchemy, which has become the standard Python library for database programming. You may use the declarative portion of SQLAlchemy like a standard ORM, but it has many more capabilities. Records provides a simple programming interface and command-line tool for SQLAlchemy.

Graphical Desktop Applications

If you are specifically interested in developing desktop applications, start with wxPython. The Tk interface toolkit that is supplied with the Python standard library is rather basic and dated. If you have advanced needs, you may prefer PySide2, which enables you to make use of the QT libraries.

Microsoft Windows Integration

Python includes support for some features that are unique to Microsoft Windows, but not all of them. To use Python with other features of Windows, such as COM and the Registry, install the win32 Extensions.

Packaging Applications

To build packaged applications for Windows, use PyInstaller or py2exe. These create stand-alone executables that include Python itself, your code, and any other dependencies.

Learning Resources

There are several excellent books for learning Python 3 that you can read for free online. Dive Into Python 3 is particularly good for those people with some previous experience of programming, especially if they are impatient! If you are not a programmer, try Automate the Boring Stuff with Python, which includes a gentle introduction to programming.

Once you have learned Python itself, visit The Hitchhiker’s Guide to Python, which provides clear advice on daily work with Python, and Full Stack Python for a comprehensive guide to building Web applications with Python.

Older article
Notes on PowerShell