0% found this document useful (0 votes)
18 views12 pages

Getting Started

This tutorial provides an introduction to Python, GitHub, and GitHub Codespaces, aimed at helping users set up their coding environment and run Python code. It covers essential tools, including VS Code and Anaconda, and offers guidance on submitting assessments through GitHub. The document also includes instructions for using the command line to navigate directories and manage files for coursework.

Uploaded by

tristanfabre.tf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views12 pages

Getting Started

This tutorial provides an introduction to Python, GitHub, and GitHub Codespaces, aimed at helping users set up their coding environment and run Python code. It covers essential tools, including VS Code and Anaconda, and offers guidance on submitting assessments through GitHub. The document also includes instructions for using the command line to navigate directories and manage files for coursework.

Uploaded by

tristanfabre.tf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Tutorial: Getting Started

Data Structures and Algorithms


Prof. Reza Skandari, Imperial College Business School

By the end of this tutorial you should have:


• Learn about different tools and environments for Python
• Open your first GitHub Codespace
• Run a few lines of code with Python

Contents
Tutorial: Getting Started 1

Part I: Setup 2
Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
GitHub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
GitHub Codespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
VS Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
GitHub Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Module’s Codespace . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Submitting Assessments . . . . . . . . . . . . . . . . . . . . . . . . 4

Part II: Running Python 5

Part III: (Optional) Local Install 7


Installing Anaconda . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Programming environments . . . . . . . . . . . . . . . . . . . . . . 9
Using the command line . . . . . . . . . . . . . . . . . . . . . . . . 9
Opening the command line . . . . . . . . . . . . . . . . . . . 10
Navigating to a folder . . . . . . . . . . . . . . . . . . . . . . 10

1
Part I: Setup
Python
Python is a popular, freely available programming language used for a broad
range of applications. It is an essential tool across academia and industry for
many data-intensive tasks, such as extracting information from large datasets,
scraping the web, and automating repetitive computations. Python is an
open-source language with an enormous community of users developing tools
around it, meaning that for fields such as analytics, there are many useful and
well-maintained tools and packages available. In practice, for any analytics
task you can think of, chances are that someone has written a package to
solve that problem.

GitHub
GitHub is a popular and freely available platform, with a different but very
useful application in the world of software engineering and data science.
GitHub is an online, cloud-based version-control and collaboration platform.
When developing large code projects, collaboration is essential, and keeping
track of different versions of your project as you add features and fix bugs is
paramount. GitHub provides online storage for your code projects, enables
version-control through a tool called ‘git’ and provides many collaborative
features for developing and sharing code with others.

GitHub Codespaces
A GitHub Codespace creates an online development environment for writing
and running code. It runs in a regular browser window and gives developers
the ability to work on their code projects from anywhere in the world. We
use GitHub Codespaces to create learning environments, giving you a robust
coding environment in the browser, so you can focus on coding faster, instead
of getting stuck configuring software on your own machine.
NOTE. Codespaces are a great way to get started and will be
sufficient for this module. However, having a local coding environ-
ment is helpful for progressing further. This document contains
instructions to install Python locally, which you can consider later.

2
VS Code
GitHub Codespaces typically run VS Code. VS Code is a free code editor
that provides many useful features for writing, fixing and running your code.
Because it is so much more than just an editor, we call it an Integrated De-
velopment Environment, or IDE for short. VS Code is one of many IDEs, but
stands out as a top choice for most developers. We will be using VS Code in
our Codespaces throughout the module.

GitHub Account
All works submitted for assessment for Data Structures and Algorithms will
be completed via Imperial GitHub Classroom. You will need to register a
GitHub account as per the ICT instructions at the provided link.

How do I gain access to GitHub Enterprise Cloud?


1. Create an account on github.com if you don’t already have one. We
recommend you use your personal email address so you can continue
to access the account if you leave Imperial.
2. Follow the instructions in the “Gaining access to the Imperial College
London organisation” article.
3. Once you’ve completed these steps, you’ll be added as a member and
will have access to all the resources.

Module’s Codespace
The links to the session Codespaces are provided on the Hub. You can access
the first session via the links below. Follow the link to the relevant assignment,
accept the assignment, and then click the Open in GitHub Codespaces
button.
• MSc Business Analytics Programme, Class 1
• All MSc Finance Programmes, Class 1
Please allow approximately 5 minutes for the Codespace to start up before
proceeding to work on any assignment. In the next section, you will find basic
information and instructions on how to use Python in Codespaces.

3
Submitting Assessments
All activities and assignments will be submitted through GitHub Codespaces.
Please follow these steps.
1. Test your work using the relevant ok commands.
2. Open the Source Control menu from the left-hand panel.
3. Enter a commit message in the message field (e.g., Completed HW 1).
4. Click the blue button once to Commit, and then click it again to Sync.
5. Verify that no files remain visible in the Source Control menu. This
indicates that your submission has been successfully synced.

4
Part II: Running Python
Now that your Codespace is running, let’s have a look at it. The figure below
shows some important areas of VS Code inside the Codespace. For now,
focus on the command-line (or, terminal) that runs along the bottom of the
Codespace window. If you cannot see this panel, you can show it using the
appropriate button near the top-right of the window.

Start the Python interpreter from the command-line by typing


python
You should be greeted by something like this (your Python version may be
different):

Python 3.12.1 (main, Dec 12 2024, 22:30:56) [GCC 9.4.0] on linux


Type "help", "copyright", "credits" or "license" for more
information.
>>>

The >>> indicates the Python prompt, which you use to communicate with
Python. This is the Python interpreter: Python is waiting for you to type in
something for it to interpret.

5
Try typing in a command:

Python 3.12.1 (main, Dec 12 2024, 22:30:56) [GCC 9.4.0] on linux


Type "help", "copyright", "credits" or "license" for more
information.
>>> print('Hello, world!')

The result should look like this:

>>> print('Hello, world!')


Hello, world!
>>>

This means that Python has interpreted you command, resulting in the display
of the text string ‘Hello, world!’ on your screen, and has also displayed a
new prompt for you to type another command. If you happened to type in
something slightly different, you may have seen an error message instead.
We will return to these in the first session; for now, try typing the command
again exactly as shown above. Now try a different command:

>>> 2 + 2

This should of course print out 4.


You can exit the Python interpreter by typing

>>> exit()

You will then return to the terminal. And you’re done!

6
Part III: (Optional) Local Install
Note: We recommend trying to use Python locally once you feel confident
working with Python, VS Code, and related tools. Please be aware that you
may encounter installation issues and risk losing valuable time troubleshooting
instead of focusing on your coursework. Ideally, you should attempt this when
you have spare time and have completed your exams.
For local installations, we will install Python with a useful collection of pack-
ages (such collections are often referred to as distributions) called Anaconda.
Advanced. If you are already comfortable with Python, you are
welcome to use a different Python distribution (with Python ver-
sion 3.11 or later). Otherwise, you should get Anaconda as it
contains all packages we will need (and more) in one convenient
download.
We recommend using the VS Code editor included with Anaconda
for writing Python code, but it is fine to use another editor too
(Spyder, PyCharm, etc).

Installing Anaconda
Please follow these instructions carefully - otherwise you may end up with
the wrong version of Python and will need to start over.
• Download the Anaconda installer here. Scroll down to find the option
for your operating system (Windows, macOS, or Linux). The download
may take a few minutes.
• Run the installer and follow its instructions, which will look similar
to the figures below, depending on your operating system. It may ask
you to make some choices; the default options should be fine. The
installation will take a while.
• The installer may prompt you to also install other software such as the
PyCharm editor; you do not need to do so.
You should now have Anaconda installed on your laptop.
• Download the VS Code installer here. Choose the correct option for
your operating system (Windows, macOS, or Linux).
• Run the installer and follow its instructions. It may ask you to make
some choices; the default options should be fine.

7
8
You should now have VS Code installed on your laptop. You can check the
successful installation of both applications by running the Anaconda Navigator
application:
• On Windows, click on the Start button or hit the Windows button and
start typing Navigator.
• On macOS, you can use Finder or Launchpad to find Anaconda Naviga-
tor.
The Navigator shows some different ways of using Python on your machine.
We will use three such programming environments in this module.

Programming environments
Programming environments are user interfaces for writing and running code.
You can think of environments as follows. You can write text documents
in both Notepad and Microsoft Word. These are “environments” for text
documents. Think of a Python program as a document and environments as
Notepad or Word.
We will use three programming environments in this module.
• The Python interpreter is a text-based interface that allows us to type
in Python-language commands to be executed line-by-line.
• VS Code is a graphical interface that combines a Python interpreter
with a text editor and various enhancements to make coding easier.
Make sure you see this in the list of environments.
• Jupyter is a browser-based interface, which allows us to create Jupyter
notebook documents that combine code and its output with narrative
text. This can be very useful for presenting and sharing your work with
colleagues, and is common practice in analytics teams.
With Anaconda installed, you are now ready to work with Python in the first
session.
In the remainder of this section, we will discuss the command-line on your
local system. We will try out the Python interpreter and look at VS Code and
Jupyter later in the course.

Using the command line


We normally interact with the computer with a mouse or a touch screen via
a graphical user interface, clicking on icons, buttons, hyperlinks, and so on.

9
The command line is an alternative text-based interface to interact with the
computer and run programs. For some tasks, it is less convenient than the
regular graphical interface we use with a mouse, but for others it gives us
more flexibility in running programs.

Opening the command line


Windows
Press the Windows key and type Anaconda Prompt. This should open the
start menu and find the Anaconda version of the Windows command line
(called “Anaconda Prompt”).

macOS
Use the Key combination Cmd-Space, type “terminal” and press Enter to open
the macOS command line (called “Terminal”).

Navigating to a folder
On Windows, the command prompt window will look something like the
figure below. The macOS view is slightly different and does not show the
current directory. Whether you are on Windows or macOS, you can follow
the steps below - we will specify the differences as we go along.

The interface shows us where we are in the computer’s file system: here, in
the directory C:\Users\hpeura. You can view the contents of the directory by
typing dir and pressing enter in Windows and ls in macOS. You should see
the same files that you see when navigating to this folder in the graphical file
explorer interface. (In Windows, you can launch the graphical file explorer
with the command explorer.)
Now, let’s create a new directory for our coursework. Type in the following
command and press Enter. (mkdir is for “make directory”.)

10
mkdir dsa

To get to the new folder, we can type in the command (cd is for “change
directory”)
cd dsa
This moves us to the folder in the directory tree. We can again see the contents
of the current folder with the command dir on Windows, and ls in macOS.
The figure below shows that currently there are no files in the folder. You can
also check that the folder now appears in the regular file explorer.

If we wish to navigate back to the parent folder, we can use the command
cd ..

11
When working locally, it is recommended to keep all the course materials
in the same folder for easy access. Ensure you can run Python from your
command-line.

12

You might also like