4 minute read
Python Step-by-Step Guide
Python will be discussed in this post to get you started, hoping to fulfill your learning needs.
Python Installation:
Advertisement
The Python programming language comes pre-installed on many PCs and Macs.
The easiest way to determine if you have Python installed on your Windows PC is to search for Python in the start bar or to run the following command on the windows command line (cmd.exe):
C:\> python –version
On both Linux and Mac operating systems, you can check whether you have Python installed by opening the terminal and typing the following code: python –version
Python Installation For Windows:
You can easily install Python on Windows and start using it right away. There are only three steps to the installation process:
1. Download Python for Windows.
2. Execute the executable installer.
3. Python should be added to the PATH environment variable.
The official Python executable installer must be downloaded in order to install Python. You will then need to run this installer and complete the installation process.
Finally, you can use Python from the command line by configuring the PATH variable. Python is available in a variety of versions. This article recommends installing Python 3.7.3, the most stable version.
Step 1: Download Python:
1. Visit the official Python for Windows website.
2. Make sure to choose the stable Python 3 release. Our example uses Python 3.7.3.
3. Download the Windows x86 executable installer if you are using 32-bit Windows. If your Windows installation is a 64-bit system, then you should download the Windows 86-64 executable installer.
Step 2: Execute the executable installer: step1 python for windows
Run the Python installer after downloading it.
Make sure the Install launcher for all users check box is checked. In addition, you may include Python 3.7 in the execution path by checking the Add Python 3.7 to path check box.
Make sure Customize installation is selected. Click the check boxes next to the optional features as shown in below Image:
1. Documentation.
2. pip.
3. tcl/tk and IDLE (to install tkinter and IDLE).
4. Python test suite (to install the standard library test suite of Python).
5. Install the global launcher for `.py` files. This makes it easier to start Python.
6 Install for all users.
1.
Python installation – optional features
Click Next: This opens Advanced options. Check the boxes below:
1. Select Install for all users.
2. Associate files with Python. (requires the py launcher)
3. Create shortcuts for installed applications.
4. Add Python to the environment variables check box.
Python Advanced Options
Take note of the Python installation directory. Install the Advanced options by clicking Install.
A Python Setup Successful window will appear after the installation is completed.
python installed successfully
Step 3: Integrating Python with environmental variables:
The final (optional) step in the Python for Windows installation process is to set the Python Path in the System Environment Variables.
Python is accessed via the command line in this step.
You can skip this step if you added Python to the environment variables at the time of setting the Advanced options during installation. Otherwise, this step must be performed manually.
Go to the Start menu and search for “advanced system settings”.
Click on “View advanced system settings”.
Select the “Advanced” tab in the “System Properties” window, then click on “Environment Variables”.
You will need to locate the Python installation directory on your computer.
You will be able to find Python in the following locations if you followed the instructions exactly as described above:
C:\Program Files (x86)\Python37-32: for 32-bit installation
C:\Program Files\Python37-32: for 64-bit installation
If you installed a different version of Python, the folder name may differ from “Python3732”.
Find a folder that starts with Python.
PATH variable should be updated as given in below example image: python env variables to the path python config env var
Step 4: Verify Python Installation:
Installing Python can either be verified through the command line or through the IDLE application that gets installed along with it. Start by typing “python” at the command prompt.
verify python installation cmd
You can see that having successfully installed Python 3.7.3 on Windows, you are now ready to use it. To get started with Python coding, use the Integrated Development Environment (IDLE).
Python Installation For Linux Operating System:
We have prepared a separate topic for step-by-step instructions on installing Python on a Linux operating system.
Python Installation For Mac Operating System:
An additional topic will be covered in order to assist you in installing Python on a Mac operating system.
Python Quickstart
A Python programmer writes python files (.py) using a text editor, then runs them in the Python interpreter using the python interpreter.
Running a Python file on the command line looks like this:
C:UsersYour Name>python tutorial.py
In above example, “pythontutorial.py” is the name of the Python file you are using. Using any text editor, let’s create our first Python file, myfirstpythonfile.py.
4 print("This is your first code in python, Congrats.")
The rest is simple. Make sure you save your file. Using the command line, navigate to the directory where you have saved your file, and run:
C:UsersYour Name>python myfirstpythonfile.py
This should be the output:
This is your first code in python, Congrats. Your first Python program has been written and executed. Congratulations!
Python in Command Line:
Whenever you want to test a short piece of Python code, you don’t have to write it to a file. Python can be run from the command line by itself, making this possible.
Run the following command on Windows, Mac, or Linux:
C:UsersYour Name>python
If the “python” command doesn’t work, try “py”:
C:UsersYour Name>py
You can then write any Python code, including our myfirstpythonfile example from earlier:
C:UsersYour Name>python
Python 3.6.4 (v3.6.4:d48eceb, Nov 30 2022, 05:04:40) [MSC v.1900 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> print(“This is your first code in python, Congrats.”)
It will display “This is your first code in python, Congrats.” in the command line:
C:UsersYour Name>python
Python 3.6.4 (v3.6.4:d48eceb, Nov 30 2022, 05:05:18) [MSC v.1900 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.