Introduction to Python including Installation, Jupyter Notebooks and Visual Studio Code

By:   |   Updated: 2024-02-28   |   Comments (1)   |   Related: > Python


Problem

What is Python programming? Is it a popular programming language? How does a programmer you install Python on Windows along with integrated development environments?

Solution

Python is a high-level or general-purpose programming language widely adopted for web development, Data Science, Machine Learning (ML) and Artificial Intelligence (AI). Python is an easy-to-understand, scalable, open-source language that allows developers to write a program with a small amount of code. It is also highly productive since it has modules and libraries for specific implementations.

Highlights of Python include:

  • Easy to learn
  • Useful in web applications
  • Used in Machine Learning
  • Used in GUI
  • Built-in mathematical functions

According to the IEEE Spectrum report, Python is the number one programming language in the general "Spectrum" ranking for 2023.

Top Programming Languages 2023

In this data science series, you can learn Python concepts, fundamentals and terminology with a deep dive into the advanced topics as we move through the software development tips.

Installing Python

Python is available on Windows, Linux/Unix, macOS, and docker containers. This tip explores the installation on the Windows operating system.

Step 1 Choose the Python Version

Python 3.12.2 is the latest version. You can download it or any active Python release from the Python website.

Download Python

Unless you require a specific release, click Download Python 3.12.2, which downloads the python-3.12.2-amd64.exe.

Step 2: Launch Install Wizard

Launch the setup and put ticks in the checkboxes highlighted below. It installs the PIP package manager, IDLE (Python editor), and additional documents with the file associations by default.

Install Python 3.12.2

We can install Python directly with default options or click on Customize installation to choose the features and location.

In the Optional Features, make sure you check all features. Click Next.

Optional features

On the Advanced Options window, choose the following options:

  • Install Python 3.12 for all users
  • Associate files with Python
  • Add Python to environment variables

You can also customize the install location. If we install Python for all users, its default location is C:\Program Files\Python.

Advanced options

Click Install. It will quickly finish the Python 3.12.2 installation, displaying the image below.

Successful setup

Step 3: Verify Installation

Use Command Prompt.

To verify the installation, launch the command prompt and run the following command:

python --version

The command should return the installed Python version (below).

Command prompt - version

If you get the error that says Python is not a recognized program, add the Python path into the environment variable.

Command prompt

To add a Python directory to the PATH environment variable, type Edit the System environment variable in the start menu.

Edit system environment variables

In the Advanced tab, locate and click on Environment Variables.

System properties

Double-click on the PATH and add the Python directory as C:\Program Files\Python312

Edit environment variables

Click OK and save the environment variable changes.

Relaunch the command prompt and run it to check the Python version; it should be successful.

Launch the Python Interpreter IDLE.

Another way to check the Python installation is to launch the Python interpreter IDLE. To do so, type IDLE in the start menu.

IDLE Shell

It launches the Python interpreter, which shows the Python version and a few keywords, such as "help", "copyright", or "license()" for more information.

Launch IDLE

You can try running the sample code to print a string "Hello, world!" in the IDLE, as shown below.

Sample code

Python Integrated Development Environment (IDE)

Python IDLE or Command-line interpreter is unsuitable for large projects or programs. You can use integrated development environments such as Visual Studio Code, PyCharm, Atom, and Jupyter Notebook. You can also use the Anaconda Python distribution, a bundled package with Python and Jupyter Notebook, and install commonly used packages and package managers.

Let's explore two popular tools: Jupyter Notebooks and Visual Studio Code (VS Code). You can use any IDE you like.

Jupyter Notebook Installation

The Jupyter Notebook is a flexible and user-friendly tool for Python. Browse the Jupyter website and click on the Jupyter Notebook -> Install the Notebook.

Jupyter Notebook Classic Notebook Interface

It gives instructions for installing the JupyterLab and notebook.

JupyterLab

However, before installing the Jupyter Notebook, we need pip (package management system) to install the packages in Python. If you do not have pip installed, it gives the following error. However, we already installed it using the custom installation.

Command prompt

To verify the pip package, run the command pip --version, which will give the output below.

Run pip

Run the command below to install Jupyterlab:

pip install jupyterlab
Command to install JupyterLab

Install the Jupyter Notebook with the below command.

pip install notebook
Install Jupyter Notebook

Launch the Jupyter Notebook with the command below.

Jupyter notebook

It opens the Jupyter URL. Click on New-> Notebook to launch a new Jupyter Notebook, as shown below.

Jupyter new notebook

You can write the code in the highlighted line. For example, let's write a sample Python code to greet the user.

def greet():
    name = input("What's your name? ")
    print("Hello, " + name + "! Nice to meet you.")
 
greet()

As shown below, we have executed the Python script in this Jupyter notebook.

Executed Python script in Jupyter notebook

Visual Studio Code Python IDE

VS Code is another popular integrated development editor (IDE) that supports multiple languages like SQL, PowerShell, and Python. It is Microsoft's IDE for Windows, Linux, and macOS, and it features intelligent code completion, code refactoring, source control, and debugging.

Download it from the VS Code website and follow the installation wizard to complete its installation.

Visual Studio Code

You need to install the Python Extension to use Python in VS Code. Click Extensions from the left-hand vertical menu bar and search for Python.

Click Install in the Python installation.

Install

After the package installation, it shows the option to disable, uninstall, or switch to the pre-release version.

Pre-release version

Relaunch VS Code. Using the Get Started with Python Development option, you can walk through Python development with VS Code.

Visual Studio Code

Otherwise, click New File from the Start links on the left side of the interface. It asks you to select the language for the new file.

Select language

Click Select a language and choose Python.

Language - Python

As shown below, write and execute the script in the VS Code Python IDE.

Write/execute script
Next Steps


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Rajendra Gupta Rajendra Gupta is a Consultant DBA with 14+ years of extensive experience in database administration including large critical OLAP, OLTP, Reporting and SharePoint databases.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips


Article Last Updated: 2024-02-28

Comments For This Article




Wednesday, February 28, 2024 - 11:40:53 AM - Aparna Pophale Back To Top (92024)
Very good article about Python!














get free sql tips
agree to terms