Share E-Book

PyTorch The Practical Guide (Bert Gollnick)(Z-Library)

Author

Rating No ratings yet

Log in to rate

Artificial Intelligence
Language English

Train and implement deep learning models with PyTorch! PyTorch is the framework for deep learning—so dive on in! Learn how to train, optimize, and deploy AI models with PyTorch by following practical exercises and example code. You’ll walk through using PyTorch for linear regression, classification, image processing, recommendation systems, autoencoders, graph neural networks, time series predictions, and language models—all the essentials. Then evaluate and deploy your models using key tools like MLflow, TensorBoard, and FastAPI. With information on fine-tuning your models using HuggingFace and reducing training time with PyTorch Lightning, this practical guide is the one you need!

Format PDF
Size 5.9 MB
7
Views
(First 20 pages)

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Page 1
(This page has no text content)
Page 2
Rheinwerk Computing Explore more of the Rheinwerk Computing library! The Rheinwerk Computing series offers new and established professionals comprehen- sive guidance to enrich their skillsets and enhance their career prospects. Our publica- tions are written by the leading experts in their fields. Each book is detailed and hands-on to help readers develop essential, practical skills that they can apply to their daily work. Bert Gollnick Generative AI with Python: The Developer’s Guide to Pretrained LLMs, Vector Databases, Retrieval-Augmented Generation, and Agentic Systems 2025, 392 pages, paperback and e-book www.rheinwerk-computing.com/6057 Joachim Steinwendner, Roland Schwaiger Programming Neural Networks with Python 2025, 457 pages, paperback and e-book www.rheinwerk-computing.com/6059 Metin Keras Developing AI Applications: An Introduction 2024, 402 pages, paperback and e-book www.rheinwerk-computing.com/5899 Mohammad Nauman Keras 3: The Comprehensive Guide to Deep Learning with the Keras API and Python 2026, 629 pages, paperback and e-book www.rheinwerk-computing.com/6142 Jason Hodson Applied Machine Learning 2026, approx. 450 pages, paperback and e-book www.rheinwerk-computing.com/6170 www.rheinwerk-computing.com
Page 3
Bert Gollnick PyTorch The Practical Guide
Page 4
Imprint This e-book is a publication many contributed to, specifically: Editor Meagan White Acquisitions Editor Hareem Shafi Translation Bert Gollnick Copyeditor Doug McNair Cover Design Abigail Damke Photo Credit iStock: 129331108/© Niko_Cingaryuk; iStock 1426271120/© imaginima Layout Design Vera Brauner Production E-Book Abigail Damke Typesetting E-Book III-satz, Germany We hope that you liked this e-book. Please share your feedback with us and read the Service Pages to find out how to contact us. Library of Congress Cataloging-in-Publication Control Number: 2026001184 ISBN 978-1-4932-2786-0 (print) ISBN 978-1-4932-2787-7 (e-book) ISBN 978-1-4932-2788-4 (print and e-book) 1st edition 2026 1st German edition published 2026 by Rheinwerk Verlag, Bonn, Germany © 2026 by: Rheinwerk Publishing, Inc. 2 Heritage Drive, Suite 305 Quincy, MA 02171 USA info@rheinwerk-publishing.com +1.781.228.5070 Represented in the E.U. by: Rheinwerk Verlag GmbH Rheinwerkallee 4 53227 Bonn Germany service@rheinwerk-verlag.de +49 (0) 228 42150-0
Page 5
Notes on Usage This e-book is protected by copyright. By purchasing this e-book, you have agreed to accept and adhere to the copyrights. You are entitled to use this e-book for personal pur- poses. You may print and copy it, too, but also only for personal use. Sharing an electronic or printed copy with others, however, is not permitted, neither as a whole nor in parts. Of course, making them available on the Internet or in a company network is illegal as well. For detailed and legally binding usage conditions, please refer to the section Legal Notes. This e-book copy contains a digital watermark, a signature that indicates which person may use this copy:
Page 6
(This page has no text content)
Page 7
Contents Preface ....................................................................................................................................................... 15 1 Introduction to Deep Learning 27 1.1 What is Deep Learning? ...................................................................................................... 27 1.2 What Can You Use Deep Learning For? ....................................................................... 28 1.3 How Does Deep Learning Work? .................................................................................... 31 1.3.1 Model Training ........................................................................................................ 31 1.3.2 Model Inference ...................................................................................................... 32 1.4 Historical Development ...................................................................................................... 33 1.5 Perceptrons .............................................................................................................................. 34 1.6 Network Structure and Layers ......................................................................................... 34 1.7 Activation Functions ............................................................................................................ 35 1.7.1 Rectified Linear Units ............................................................................................ 36 1.7.2 Hyperbolic Tangents ............................................................................................. 37 1.7.3 Sigmoid ...................................................................................................................... 37 1.7.4 Softmax ..................................................................................................................... 37 1.8 Loss Functions ......................................................................................................................... 38 1.8.1 Regression Problems ............................................................................................. 39 1.8.2 Binary Classification .............................................................................................. 39 1.8.3 Multiclass Classification ...................................................................................... 40 1.9 Optimizers and Updating Parameters ......................................................................... 40 1.9.1 Optimizers ................................................................................................................ 40 1.9.2 Updating Parameters ............................................................................................ 41 1.10 Tensor Handling ..................................................................................................................... 42 1.10.1 What are Tensors? ................................................................................................. 43 1.10.2 Coding: Tensor Creation and Attributes ......................................................... 43 1.10.3 Coding: The Calculation Graph and Training ................................................ 45 1.11 Summary ................................................................................................................................... 507
Page 8
Contents2 Creating Your First PyTorch Model 51 2.1 Data Preparation ................................................................................................................... 51 2.1.1 Feature Types ........................................................................................................... 52 2.1.2 Data Types ................................................................................................................ 54 2.1.3 One-Hot Encoding .................................................................................................. 54 2.1.4 Exploratory Data Analysis ................................................................................... 56 2.1.5 Data Scaling ............................................................................................................. 59 2.2 Model Creation ....................................................................................................................... 60 2.2.1 Data Import .............................................................................................................. 61 2.2.2 Model Training ........................................................................................................ 62 2.2.3 Model Evaluation ................................................................................................... 64 2.2.4 Model Inference ...................................................................................................... 65 2.3 The Model Class and the Optimizer .............................................................................. 68 2.4 Batches ....................................................................................................................................... 72 2.4.1 What Are Batches? ................................................................................................. 72 2.4.2 Advantages of Using Batches ............................................................................. 72 2.4.3 Optimal Batch Size ................................................................................................. 73 2.4.4 Coding: Implementation of Batches ................................................................ 74 2.5 Coding: Implementation of Dataset and DataLoader .......................................... 76 2.6 Loading and Saving a Model ............................................................................................ 80 2.6.1 Saving Model Parameters .................................................................................... 80 2.6.2 Loading a Model ...................................................................................................... 81 2.7 Data Sampling ........................................................................................................................ 83 2.7.1 What Is Data Sampling? ....................................................................................... 83 2.7.2 Cross-Validation ..................................................................................................... 85 2.7.3 Why Is Data Sampling Needed? ........................................................................ 85 2.7.4 Coding: Separation of Training and Validation Data ................................. 86 2.8 Summary ................................................................................................................................... 92 3 Classification Models 93 3.1 Classification Types .............................................................................................................. 93 3.2 Confusion Matrix ................................................................................................................... 95 3.3 Receiver Operator Characteristic Curve ...................................................................... 97 3.4 Coding: Binary Classification ........................................................................................... 99 3.4.1 Data Preparation .................................................................................................... 998
Page 9
Contents3.4.2 Modeling ................................................................................................................... 104 3.4.3 Evaluation ................................................................................................................. 108 3.5 Coding: Multiclass Classification .................................................................................... 112 3.5.1 Data Preparation .................................................................................................... 113 3.5.2 Modeling ................................................................................................................... 117 3.5.3 Evaluation ................................................................................................................. 121 3.6 Summary ................................................................................................................................... 124 4 Computer Vision 127 4.1 How Do Models Handle Images? .................................................................................... 128 4.2 Network Architecture .......................................................................................................... 129 4.2.1 Convolutional Neural Networks ........................................................................ 130 4.2.2 Vision Transformers .............................................................................................. 132 4.3 Coding: Image Classification ............................................................................................ 134 4.3.1 Binary Classification .............................................................................................. 135 4.3.2 Multiclass Classification ...................................................................................... 151 4.4 Object Detection .................................................................................................................... 163 4.4.1 How Does Object Detection Work? .................................................................. 164 4.4.2 Data Preparation .................................................................................................... 165 4.4.3 Model Training ........................................................................................................ 171 4.4.4 Model Evaluation ................................................................................................... 172 4.4.5 Model Inference ...................................................................................................... 175 4.5 Semantic Segmentation ..................................................................................................... 178 4.5.1 How Does Semantic Segmentation Work? ................................................... 179 4.5.2 Segmentation Masks ............................................................................................ 180 4.5.3 Data Preparation .................................................................................................... 181 4.5.4 Model Training ........................................................................................................ 182 4.5.5 Model Evaluation ................................................................................................... 186 4.6 Style Transfer .......................................................................................................................... 188 4.6.1 How Does Style Transfer Work? ........................................................................ 189 4.6.2 Data Preparation .................................................................................................... 190 4.6.3 Model Training ........................................................................................................ 193 4.6.4 Model Evaluation ................................................................................................... 196 4.7 Summary ................................................................................................................................... 1979
Page 10
Contents5 Recommendation Systems 199 5.1 Theoretical Foundations ..................................................................................................... 199 5.1.1 Basic Concepts ......................................................................................................... 199 5.1.2 Matrix Factorization .............................................................................................. 201 5.2 Coding: Recommendation Systems .............................................................................. 202 5.2.1 Data Preparation .................................................................................................... 202 5.2.2 Modeling ................................................................................................................... 206 5.2.3 Model Evaluation ................................................................................................... 209 5.3 Summary ................................................................................................................................... 218 6 Autoencoders 219 6.1 Architecture ............................................................................................................................. 220 6.2 Coding: Autoencoder ........................................................................................................... 220 6.2.1 Data Preparation .................................................................................................... 221 6.2.2 Modeling ................................................................................................................... 223 6.2.3 Model Training ........................................................................................................ 226 6.2.4 Model Validation .................................................................................................... 228 6.3 Variational Autoencoders .................................................................................................. 230 6.4 Coding: Variational Autoencoder .................................................................................. 231 6.4.1 Network Architecture ........................................................................................... 231 6.4.2 Loss Function ........................................................................................................... 235 6.5 Summary ................................................................................................................................... 240 7 Graph Neural Networks 241 7.1 Introduction to Graph Theory .......................................................................................... 241 7.1.1 Graphs and the Adjacency Matrix .................................................................... 242 7.1.2 Features ..................................................................................................................... 243 7.1.3 Passing Messages ................................................................................................... 244 7.1.4 Use Cases .................................................................................................................. 245 7.2 Coding: Developing a Graph ............................................................................................ 246 7.3 Coding: Training a Graph Neural Network ................................................................ 250 7.4 Summary ................................................................................................................................... 25910
Page 11
Contents8 Time Series Forecasting 261 8.1 Modeling Approaches .......................................................................................................... 261 8.1.1 Special Features of Time Series Models .......................................................... 261 8.1.2 Data Modeling ......................................................................................................... 262 8.1.3 Long Short-Term Memory ................................................................................... 263 8.1.4 One-Dimensional Convolutional Neural Networks .................................... 264 8.1.5 Transformer .............................................................................................................. 265 8.2 Coding: Custom Model ....................................................................................................... 266 8.2.1 Data Preparation .................................................................................................... 266 8.2.2 Long Short-Term Memory ................................................................................... 271 8.2.3 Convolutional Neural Network .......................................................................... 274 8.2.4 Transformers ............................................................................................................ 277 8.3 Coding: Using PyTorch Forecasting ............................................................................... 280 8.3.1 Data Preparation .................................................................................................... 280 8.3.2 Model Training ........................................................................................................ 284 8.3.3 Evaluation ................................................................................................................. 286 8.4 Summary ................................................................................................................................... 288 9 Language Models 289 9.1 Using Large Language Models with Python .............................................................. 290 9.1.1 Coding: Using OpenAI ........................................................................................... 291 9.1.2 Coding: Using Groq ................................................................................................ 294 9.1.3 Coding: Multimodal Models ............................................................................... 297 9.1.4 Coding: Using Large Language Models Locally ............................................ 300 9.2 Model Parameters ................................................................................................................. 304 9.2.1 Model Temperature ............................................................................................... 304 9.2.2 Top-p and Top-k ...................................................................................................... 305 9.2.3 Best Practices ........................................................................................................... 307 9.3 Model Selection ...................................................................................................................... 307 9.3.1 Performance ............................................................................................................. 307 9.3.2 Cutoff Date ............................................................................................................... 308 9.3.3 On-Premise Versus Cloud Hosting ................................................................... 309 9.3.4 Open-Source, Open-Weight, and Proprietary Models ............................... 309 9.3.5 Cost ............................................................................................................................. 309 9.3.6 Context Window .................................................................................................... 310 9.3.7 Latency ....................................................................................................................... 31011
Page 12
Contents9.4 Message Types ........................................................................................................................ 310 9.4.1 User/Human Messages ........................................................................................ 310 9.4.2 System Messages ................................................................................................... 311 9.4.3 Assistant Messages ............................................................................................... 311 9.5 Prompt Templates ................................................................................................................. 311 9.5.1 Coding: ChatPromptTemplates ......................................................................... 312 9.5.2 Coding: Improving a Prompt with LangChain Hub ..................................... 313 9.6 Chains ......................................................................................................................................... 315 9.6.1 A Simple Sequential Chain .................................................................................. 315 9.6.2 Coding: A Simple Sequential Chain .................................................................. 316 9.7 Structured Outputs ............................................................................................................... 317 9.7.1 What Are Structured Outputs? .......................................................................... 317 9.7.2 Coding: Structured Outputs ............................................................................... 318 9.8 Deep Dive: How Do Transformers Work? ................................................................... 320 9.8.1 Tokenization ............................................................................................................. 321 9.8.2 Word Embeddings .................................................................................................. 323 9.8.3 Positional Encoding ............................................................................................... 324 9.8.4 Attention ................................................................................................................... 325 9.9 Summary ................................................................................................................................... 327 10 Pretrained Networks and Fine-Tuning 329 10.1 Pretrained Networks with Hugging Face ................................................................... 329 10.2 Transfer Learning ................................................................................................................... 332 10.2.1 Advantages of Transfer Learning ...................................................................... 332 10.2.2 Transfer Learning Approaches ........................................................................... 334 10.3 Coding: Fine-Tuning a Computer Vision Model ....................................................... 335 10.3.1 Data Preparation .................................................................................................... 336 10.3.2 Model Training ........................................................................................................ 339 10.3.3 Model Evaluation ................................................................................................... 341 10.4 Coding: Fine-Tuning a Language Model ..................................................................... 343 10.4.1 Data Preparation .................................................................................................... 344 10.4.2 Model Training ........................................................................................................ 346 10.4.3 Model Evaluation ................................................................................................... 348 10.5 Summary ................................................................................................................................... 34812
Page 13
Contents11 PyTorch Lightning 351 11.1 PyTorch Versus PyTorch Lightning ................................................................................. 351 11.2 Coding: Model Training ...................................................................................................... 352 11.3 Callbacks .................................................................................................................................... 359 11.3.1 Model Checkpoints ................................................................................................ 359 11.3.2 Early Stopping .......................................................................................................... 361 11.4 Summary ................................................................................................................................... 362 12 Model Evaluation, Logging, and Monitoring 363 12.1 TensorBoard ............................................................................................................................. 363 12.1.1 How It Works ........................................................................................................... 364 12.1.2 Using TensorBoard ................................................................................................. 364 12.1.3 TensorBoard Dashboard ...................................................................................... 370 12.2 MLflow ........................................................................................................................................ 372 12.2.1 Data Logging ............................................................................................................ 373 12.2.2 Saving and Loading the Model ........................................................................... 375 12.2.3 MLflow Dashboard ................................................................................................. 376 12.3 Weights & Biases: WandB ................................................................................................. 377 12.3.1 Initialization ............................................................................................................. 378 12.3.2 Logging Metrics ....................................................................................................... 379 12.3.3 Logging Artifacts ..................................................................................................... 380 12.3.4 Sweeps ....................................................................................................................... 382 12.4 Summary ................................................................................................................................... 384 13 Deployment 385 13.1 Deployment Strategies ....................................................................................................... 385 13.2 Local Deployment .................................................................................................................. 387 13.2.1 API Development .................................................................................................... 388 13.2.2 Deployment .............................................................................................................. 391 13.2.3 Test .............................................................................................................................. 391 13.3 Heroku ........................................................................................................................................ 393 13.3.1 Command Line Interface and Login ................................................................. 393 13.3.2 Deployment .............................................................................................................. 39413
Page 14
Contents13.3.3 Test .............................................................................................................................. 397 13.3.4 Stopping and Deleting the App ......................................................................... 398 13.4 Microsoft Azure ...................................................................................................................... 399 13.4.1 First Steps .................................................................................................................. 399 13.4.2 App Development .................................................................................................. 401 13.4.3 Local Test ................................................................................................................... 403 13.4.4 Function App Development in the Azure Portal .......................................... 404 13.4.5 Cloud Deployment ................................................................................................. 406 13.5 Summary ................................................................................................................................... 407 The Author ............................................................................................................................................... 409 Index .......................................................................................................................................................... 411 Service Pages .....................................................................................................................................  I Legal Notes .........................................................................................................................................    II 14
Page 15
Preface Welcome to your journey into the world of deep learning with PyTorch—the most pop- ular open-source deep learning framework! It provides a comprehensive library of tools for deep neural networks, which makes it a foundational platform for developing and training state-of-the-art deep learning models. In this preface, you’ll find out what you can expect to learn from this comprehensive guide. My goal goes beyond mere knowledge transfer. I want to empower you to use deep learning in a targeted way and fully prepare you to tackle and master the challenges and opportunities that this technology brings to the modern world. By the end of your jour- ney through this book, you’ll have achieved not only an understanding but also a mas- tery of the complex tools of artificial intelligence (AI). Target Group This book is aimed at a broad target group interested in deep learning with PyTorch, including students of computer science, mathematics, and related disciplines as well as professionals who want to expand their knowledge in this area. The book is written in such a way that a beginner in machine learning can work with it, but experienced pro- fessionals can also use it to improve their skills and knowledge. The practical examples and detailed explanations will help you understand the con- cepts and techniques that are crucial for the development and application of deep learn- ing. Whether you want to innovate in your field, start an academic project, or simply explore your fascination with AI, this book should be a valuable resource on your jour- ney. Requirements Before we dive into the captivating world of deep learning, there are a few prerequisites you should keep in mind to ensure a smooth journey. First, you need to have a good understanding of Python programming. You should feel comfortable with the follow- ing: ▪ The creation of functions ▪ Working with different data structures like lists or dictionaries ▪ Manipulating these structures ▪ Writing loops (mainly for loops) ▪ Using packages like numpy and pandas15
Page 16
PrefaceIdeally, but not necessarily, you should already have a basic understanding of machine learning concepts, such as training models with scikitlearn and working with datasets. Familiarity with basic statistics and linear algebra will also be an advantage as they underpin many AI algorithms. If these prerequisites sound like languages you speak, you’re well equipped to master the challenges that lie ahead when training neural net- works. Structure of the Book The book is intended as a practical guide for Python programmers who want to develop AI applications. The structure of the book follows a step-by-step approach, starting with an introduction to the basic concepts and progressing to more advanced topics. You’re encouraged to go through the book in order, as some chapters build on knowledge from previous chapters—more on this in the next section. Chapter 1 provides an introduction to deep learning, covering the basic building blocks such as neural networks, activation functions, and tensors to provide a solid theoretical foundation. Chapter 2 leads you seamlessly to the creation and training of your first model, which will be a regression model. Chapter 3 will expand your knowledge of training classification models with the aim of being able to predict two or more classes. You’ll also learn where you need to make changes to adapt the model training to new tasks, such as other classifications. Chapter 4 is the most extensive chapter, as there are an extremely large number of tasks and models in the field of computer vision. It begins with image classification using convolutional neural networks (CNNs), which constitute a fundamental technique for many image processing tasks. It follows this up with more complex applications such as style transfer, in which the artistic and visual style of one image is transferred to another, as well as object recognition and semantic segmentation, which make it possi- ble to localize and classify objects in images. Chapter 5 begins with a basic introduction to the topic of recommendation systems and presents the different types of recommendation systems and their areas of application. It then covers the theoretical foundations of recommendation systems, including the various algorithms and techniques used. Chapter 6 introduces the world of autoencoders and variational autoencoders (VAEs), two powerful architectures. After a basic introduction and an explanation of the theo- retical principles, the focus is on the practical implementation using the Python-based framework PyTorch. Through detailed example code, you’ll learn how to implement both simple autoencoders and more complex VAEs in PyTorch. We’ll highlight the dif- ferences between and application areas of the two architectures.16
Page 17
PrefaceChapter 7 discusses graph neural networks (GNN), which you can use to model complex relationships in networked data. It covers both the theoretical foundations of GNNs and practical implementations of them with PyTorch, to help you use GNNs for a variety of applications. Chapter 8 covers the prediction of time series, which is a central application area of recurrent neural networks (RNNs). RNNs, and in particular long-short term memory (LSTM), were developed to process sequential data. They have a “memory” that enables them to store information from past timesteps. Chapter 9 introduces the world of natural language processing (NLP) with PyTorch. It covers the basic concepts and architectures required for understanding and developing large language models. Chapter 10 deals with the concept of fine-tuning, in which pretrained models are adapted to specific tasks to improve performance and reduce training effort. It also dis- cusses parameter-efficient fine-tuning (PEFT), a method that aims to minimize the num- ber of trainable parameters and thus reduce memory requirements and computational costs. It also discusses other related techniques and considerations. Chapter 11 introduces a new framework—PyTorch Lightning—since by then, you’ll have acquired a basic understanding of working with PyTorch, which forms the basis for understanding neural networks. PyTorch Lightning builds on this foundation and sim- plifies and abstracts the work, especially the training process, so that you can focus more on the model and the data. Through example code, we’ll demonstrate the practi- cal application of PyTorch Lightning, focusing on the clear organization of the code and the automatic handling of training sequences. Finally, we’ll discuss the implementation of early stopping, which is an important technique for avoiding overfitting and optimiz- ing the training process. Chapter 12 covers model evaluation, which is an essential task that’s closely linked to model development. It begins with a basic introduction to the various metrics and methods used to evaluate the performance of models. The focus here is also on practical applications, with detailed coding examples illustrating the use of MLflow, Tensor- Board, and Weights & Biases (WandB). These tools make it possible to monitor the train- ing process, visualize metrics, and evaluate models more efficiently. Chapter 13 rounds out the book by dealing in detail with deploying a trained model, which is a key step in making trained deep learning models usable in real applications. It starts with a general introduction to the different aspects of model deployment, including challenges and best practices. Also note that practical Python code examples are available for download to illustrate and consolidate the application of the concepts we discuss.17
Page 18
PrefaceHow to Use This Book This book is intended both as a practical tool for enthusiasts, developers, and profes- sionals and as a comprehensive guide for anyone who wants to learn about and control the power of AI. Most chapters are stand-alone, and you can simply jump into them after you’ve gained an understanding of some of the basics. See Figure 1 for an overview of the chapters and their dependencies. Figure 1 Chapter Dependencies The information Chapter 1 is considered fundamental for understanding all subsequent chapters, and Chapter 2 lays the foundations for all the models you will train. So, you should read them first, and then, you’ll be free to decide which topics interest you the most and read only the chapters on them if you wish. However, Chapter 9 is a special case. The models in it are handled somewhat differently because they place immense demands on the complexity of the network as well as the amount of data for training. So, you probably won’t want to train a language model from scratch when working on Chapter 9—instead, it’s best to use an existing language model to eliminate some of the requirements. That means you can jump into Chapter 9 as soon as you’re done reading Chapter 1, which will familiarize you with the basics of deep learning. Downloading Code and Additional Materials You can download the code you’ll use in this book so that you can reproduce the scripts yourself. You can obtain the material via GitHub at https://github.com/DataScience- Hamburg/PyTorch_Book_Material.18
Page 19
PrefaceThe following section describes how to download the material so that you can follow the Python scripts on your own system. Preparing the System Figure 2 shows the steps you should perform to set up the system so that you can work with the code material and run it on your local system. Figure 2 System Setup Steps These steps may seem like a lot, but remember that this is only a one-off and should not take longer than 30 minutes. Installing Python Installing Python is very simple, and you can do it in different ways. I recommend downloading Python from the official website: https://www.python.org/downloads/. If you scroll down a bit on the download page, you’ll find different versions. Figure 3 shows a list of different versions of Python. The code in this book was devel- oped based on Python version 3.12.7, so to avoid problems, you should use the same ver- sion. Please click on the Download button and follow the installation instructions. There is nothing special to note, and you can use the default settings. On some systems, such as MacOS, Python is already preinstalled. You can type “python -version” in the command line to find out which Python version is installed. 4. Course Material Download 5. Python Environment Setup 3. Git-Installation 2. IDE-Installation or Cursor Visual Studio Code 1. Python- Installation19
Page 20
PrefaceFigure 3 Python Versions Installing an Integrated Development Environment You need to have an integrated development environment (IDE) to efficiently write and manage code in Python projects. Popular options are as follows: ▪ Visual Studio Code (VS Code) This is a lightweight and highly customizable IDE that supports many different pro- gramming languages. That’s one reason why it’s one of my favorites. I can use VS Code for my Python, R, and Flutter projects, and I don’t have to get used to a different IDE when I switch projects. VS Code is open source, and you can download it for free from https://code.visuals- tudio.com/. It also has a large community that provides thousands of extensions. I used it for many years and could hardly imagine switching—but recently, I did and switched to Cursor. ▪ Cursor This is a fork of VS Code, which means it’s a very close relative. It has an AI-assisted code editor built in, and with it, you’ll become much faster and more efficient at pro- gramming. It leverages the capabilities of generative AI, and you can get coding assis- tance via OpenAI’s Codex, GPT, or Claude. Cursor offers features such as code completion, code explanation, debugging, refac- toring, and interactive chat. There is a free version and a paid version, and you can find out more at https://www.cursor.com/. You’ll also need to create an account to use the program.20
The above is a preview of the first 20 pages. Register to read the complete e-book.

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
← Back to List