Installation

You need the right tool for a specific job. Can you imagine trying to use a tape measure to hammer a nail? Ok, so you have probably already tried that and broke the tape measure. But it would be more effective if you had a hammer, the correct tool, to hammer the nail. Application development requires that you have a set of tools in your toolbox for a specific task.

Python

Developing in Python will require you first and foremost to download and install the Python language on your computer. Python can be installed on a variety of operating systems (Windows, Mac OS X, Linux/UNIX). The link to visit for downloading Python is https://www.python.org/downloads/. If you have a Windows computer, then you will of course choose the Windows link. If you have a Mac, you will choose the Mac OS X link.

NOTE: Mac users, be aware that currently Python 2.7 is most probably already installed on your system. But you need to install the latest version as described in this section.

By default, the Windows version of Python is a 32-bit version. When choosing which version of Python to download and install, you must decide if you want to download the 32-bit or 64-bit version. What is the difference? Many of the newer computers have a 64-bit processor. When a computer is made, the processor is the “brain.” A 64-bit processor is more capable than a 32-bit processor because it can handle more data. It also performs more efficiently in computations and accessing memory. A 32-bit processor can only access 4 GB of ram or less in Windows, which is why most computers have a 64-bit processor and also why Windows and Mac OS X are 64-bit operating systems. For this reason, we will NOT use the default download for Windows (Mac users are fine using the default) and instead choose a different download as shown in the video below.

NOTE: Some older computers might be running a 32-bit operating system.

For this reason—and although there is some debate as to whether the 32-bit Python environment is more stable than the 64-bit Python environment–you should download and install the 64-bit version. When you try to install it, the program should inform you if your system cannot install a 64-bit version, in which case you would download and install the 32-bit version of Python.

NOTE: For this course, we will be demonstrating how to install and use Python in a Windows environment. When you see the different versions of Python you can download, you will see a Windows x86 option. Although 86 is a larger number than 64, it is the 32-bit version. The reason is that in the past, computers had an 8086 (1978), 80286 (1982), 80386 (1985), or 80486 (1989) processor which executed a 32-bit environment. Software applications adopted the x86 notation to represent a 32-bit application.

The current version of Python is now 3.10.6 and is constantly being updated. The download link is https://www.python.org/downloads/, and then you will need to choose the version of Python you want to use.

Figure 1.4:

As you watch this video, make sure you pay close attention to the comment of clicking the checkbox that says “Add Python 3.10 to PATH.”

Figure 1.5:

If you do not do that, then you will either have to reinstall or manually change the environment path. Here is the video to install Python on a Windows computer:

Confirm Installation Worked

One way to confirm whether or not Python installed correctly is to go to the command line (or open the terminal window) and type in the word Python and press Enter.

If you see something like the following, then it installed correctly:

NOTE: Mac users, since Python 2.7 was already installed on your system, you will want to type python3 at the prompt.

            Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1924 64 bit (AMD64)] on win32
            Type "help", "copyright", "credits" or "license" for more information.
            >>>
            

NOTE: You can press the Ctrl+Z and the Enter key to exit Python and then close the terminal window.

If you see something like:

            'Python' is not recognized as an internal or external command,
            operable program or batch file.
            

then it might have installed but either needs you to reboot the computer or add an environment variable to the path.

NOTE: For those working on MacOS, if Python is not recognized, that is probably because the path was not modified. Visit this link for more help: MacOS modify path.

If after rebooting the computer the Python command still does not work, the error message might say something about the path. You might have forgotten to click the checkbox as stated above before the installation video.

NOTE: You will only need to do this if Python was not recognized in the command window. Here is a video that shows you how to update your Windows environment path:

Now that you have installed Python on your computer, we need to add the rest of the tools to your development toolbox.

Visual Studio Code

We have added our programming language (Python) to our toolbox. You will need some type of tool that will allow you to type in programming language statements, confirm that the syntax or rules are followed correctly, and provide the ability to run the application. This is called an IDE (Integrated Development Environment). There are many different IDEs popular in Python:

  1. Eclipse plus PyDev

  2. Sublime Text

  3. Atom

  4. PyCharm

  5. Visual Studio Code

In order to learn how to play the piano, you must have some type of piano so that you can practice! So, to learn how to practice in Python, you need to download and install the Python development environment. Our “piano” will be Visual Studio Code.

Microsoft’s Visual Studio Code is a free, open source (meaning the programming statements used to create VS Code is available for anyone to download and modify) development environment. It has a code editor to write Python programming statements, takes little space to install on your computer, can run on a variety of operating systems (i.e., Windows, Linux, Mac OS X, etc.) and is configurable to work with Python to provide access to many Python add-on packages (libraries of code already written to perform specific tasks and make your life easier as a software developer).

Microsoft’s Visual Studio Code can be downloaded for free by visiting the Download Visual Studio Code page. You will want to click on your computer’s operating system to make sure the correct version is downloaded.

Git and GitHub

Another tool that is widely used by developers is called Git, and it is a software application that performs version control. A software developer can use Git to manage and control your source code history. Much like checking a book out of the library, a developer can “check out” pieces of source code from the repository (like a library of programs). After completion, the developer can check the changed code back into the library, which in turn will determine what it should do with the changes (i.e., overwrite, discard, compare, etc.).

Not only does this assist you in maintaining current versions of your software, but it also creates an environment of collaboration with other developers that could be working with you on creating an application. The Git software will help keep track of when/who has “checked out” the program to modify it and when/who has “checked the code back in” to the repository (library). The Git software helps determine whose changes were the latest changes made and then keeps those changes and discards older changes. In other words, Git focuses on version control and code sharing. It is installed locally and primarily accessed through non-graphical commands.

The link to download Git is Git Download.

NOTE: As of this writing, the current version was 2.33.0.

An add-on program to make Git easier to use is called GitHub, and it is a cloud-based hosting service that provides a graphical interface to manage the Git repositories and simplifies the collaboration effort. It focuses on a centralized source code hosting area using a visual environment instead of the default command-line Git environment. It is also built for collaborative team development in making the sharing of source code easier and more straightforward.

The link to download GitHub is GitHub Download.

NOTE: As of this writing, the current version is 2.9.3.

You do NOT need GitHub to use Git, but it does allow you to share your repositories with others, access other users’ repositories, and store backup copies of your local repositories.

How to Install Git

How to Install GitHub

By the end of this course, you will learn how to use GitHub to develop and maintain Python software in a collaborative environment, but until then, you will start with the basics of only using Git. You will learn how to use GitHub in a later chapter.

Installing Extensions to Make Life Easier

Now that you have installed the Python language/interpreter, Visual Studio Code, and Git, you are ready to start writing your first Python program. For Visual Studio Code (VS Code) to assist you in writing Python source code, you need to install a Python Extension. You do not need to do this, but your software development process would be like digging a deep hole using only a cup as your shovel. You can get the job done, but it will not be as easy as using a tool suited for the job. An extension allows you to add support to the VS Code environment making development quicker, easier, and more readable. There are several free extensions created by the Python community of developers with the intent of improving the overall development experience, and they can easily be installed in VS Code. Some of those extensions are:

  • Python plug-in from Microsoft

  • Django

  • GitLens

  • Live Server

There are many more, so before you start complaining about a lack of a specific feature in the VS Code’s development environment, check to see if someone has already solved that problem and made your life easier. In fact, one way to confirm whether a plug-in is widely used is to view the number of downloads by the Python community.

Extensions in VS Code can be installed any time. The videos below show how to install each of the extensions listed above.

A new extension released by Microsoft is called Pylance. Microsoft said that Pylance is a “fast and feature-rich language support for Python in Visual Studio Code” and is an enhancement to the Python Langauge Server.

Python Plug-In from Microsoft

This extension helps VS Code to understand that you are writing a program using the Python language and includes many features such as IntelliSense (code completion), debugging, testing, linting (helps identify errors), code formatting, code navigation, and more! The most popular Python plug-in, and the one we want to install, was created by Microsoft.

The extension should say “IntelliSense (Pylance), Linting, Debugging (multi-threaded, remote), Jupyter Notebooks, code formatting, ...”

NOTE: The Python extension from Microsoft might automatically be installed into Visual Studio for you. If there is not an “Install” button, then it most probably is already installed. You can confirm this by clicking on the extension and seeing if the “Uninstall” button is displayed.

Django

This extension installs a web framework that improves development of Python applications. Your computer is called the Client. The Client has an internet browser installed as an application. This browser’s job is to take HTML data and render it (Draw) on your screen. The code that runs on your machine (Client) is called the “front-end” and represents the front-side or client-side of the internet. When you type in a uniform resource locator (URL), in other words a web address, the browser on the client (your computer) sends a request in the form of a packet of information through your router on to the internet communication “highway” that consists of many routers. Each router’s job is to know how to move the packets of information from one location to another until they reach the desired destination. This packet of information will be sent (called a “hop”) through multiple routers until it is finally directed to the correct router. It seems like magic, but since the internet users adhere to a set of Internet Protocols (IP), all the routers know how to work with the packets and communicate with other routers. Once you arrive at your URL destination, you encounter a web server, which stores all the necessary files you need to request to view a specific website. The web server (also called the server-side or back-end) is simply a computer that is connected to the internet and allows other computers to access its information (i.e., HTML pages, database, videos, etc.).

Figure 1.6: How the Internet Works

A web framework is a software application that supports building web applications. Think of it as a software library that makes web development easier and quicker. They can assist the developer in a variety of programming tasks that otherwise would take an ample amount of time to complete. They can make working with a database easy by simply using the framework’s pre-written code. They can also do things such as support web form inputs and validations along with URL routing and security. Some of these tasks might not make much sense yet, but as you continue to develop a website, you will see that a framework allows you to complete your project in less time and with greater ease.

Django is one of the most popular web frameworks with Python (another one is Flask). The web framework must be installed on the server-side so that when users visit your website via a URL, the server uses the web framework to help accomplish the user’s request (i.e., logging in, retrieving data from a database, downloading a video, etc.).

NOTE: When installing the Django extension, don't worry about the extension not matching the video. Instead, look for the Django extension written by Baptiste Darthenay.

GitLens

This extension enhances Git capabilities in VS Code by helping developers visualize program authorship. Remember that Git is used to control different versions of your website. However, using Git means that you will be typing in a lot of commands rather than visually seeing the history of the version control. It allows you to visually identify by whom, why, and when a line of source code has been created, edited, or deleted. As you work with your Python source code in Visual Studio Code, this extension will visually show you the history of the code as it has been changed in your file.

NOTE: Install the GitLens extension written by Eric Amodio.

Live Server

This extension launches a local development server simulating the deployment or installation of your Python application. As shown above in how the internet works, once you have created your website, you will need to upload your HTML pages, database, and any other needed files to the web server. The web server “hosts” your web pages and allows people to visit your website. You are able to test your website without having to purchase a hosting plan to set up a real web server during development time. Instead, you can simulate a web server on your computer (called localhost). In other words, your computer will act as the client-side (front-end or browser) and the server-side (back-end or host). Once you develop and test your website, you can then deploy or install your website to an internet host with a web server attached to the internet for anyone to visit. Be aware that during development, using a local host means that only you will access your website. It will not be visible for the public to access your website until you deploy your content (HTML web pages, etc.) to the web server.

Live Server simulates a web server on your computer called localhost and is used during development of your website for testing how the website would execute if on the internet.

NOTE: Install the Live Server by Ritwick Dey.