Installation of python#
Step 1: Install VS Code#
VS Code is an advanced text editor for python files. We will use it to both edit python source files and run the python programs.
Install VS Code for your platform:
Download and install VS Code from https://code.visualstudio.com/Download/
Use the default settings during install
Full details available from: https://code.visualstudio.com/docs/setup/mac.
Download Visual Studio Code for macOS from https://code.visualstudio.com/Download/.
Open the browser’s download list and locate the downloaded app or archive.
If VS Code was downloaded a
.zip
-file, extract the archive contents. Use double-click for some browsers or select the ‘magnifying glass’ icon with Safari.Drag
Visual Studio Code.app
to the Applications folder, making it available in the macOS Launchpad.Open VS Code from the Applications folder, by double clicking the icon.
Add VS Code to your Dock by right-clicking on the icon, located in the Dock, to bring up the context menu and choosing Options, Keep in Dock.
On Ubuntu the simplest way is to use snap:
sudo apt install snap
sudo snap install --classic code
For additional distribution-specific instructions please see https://code.visualstudio.com/docs/setup/linux.
Need help?
If you run into issues following the instruction guide, you can get help from the Python support.
- Python support
Step 2: Install Python#
To run Python files, you must have a Python interpreter installed. The interpreter is responsible for actually running your programs.
First check if you already got a suitable version installed. From the VS Code terminal, type the exact phrase:
python --version
. If you have Python installed, this will print out the version number. If it isPython 3.8
or greater: Go ahead! skip to step 3.
Click on the link starting with Python 3.11.
Scroll to the bottom of the page and choose Windows installer (64-bit).
Install the downloaded file by following the instructions.
Important: Make sure to check the option Add python 3.11 to PATH during the installation.
Follow these instructions https://www.dataquest.io/blog/installing-python-on-mac/.
Since there are many linux distributions, you may have to google your way to a solution. However, on Ubuntu, running
sudo apt install -y python3-pip python3.10 python-is-python3
should do the trick.
The latest linux distributions changed the way python is installed. This mean you have to follow slightly alternative instructions, specifically, you must use a so-called virtual environment. The steps are a little more complicated, but once you are done, it will not affect how Python works.
First, install (or rather, make sure you have) a base version of Python:
sudo apt-get update
sudo apt-get install python3-venv
The virtual environment is a special folder which will contain a separate version of Python. I recommend installing it in your home folder for simplicity as follows:
python3 -m venv ~/venv
Then whenever you need to use Python in a terminal, type the following:
source ~/venv/bin/activate
and you can now use Python as normal. When you install packages, they will be put in the ~/venv
-folder.
Finally, in VS Code, when you are prompted to select the interpreter, you need to navigate and open the interpreter located at ~/venv/bin/python
.
Step 3: Install the Python extension for VS Code#
To enable Python support in VS Code, you must install the Python extension. To do this:
From the activity bar, click on the icon with the four boxes indicated in the screenshot.
This will open a pane. Type python in the search field and hit enter
Install the Python extension (top most search hit). It will have Microsoft as publisher.
Step 4: Get the course software and exercises#
To get started, you must first download the course folder to your computer:
You can download the folder as a zip
-file:
Once downloaded, extract the zip
-archive.
Rename the folder from 02002students-master
to 02002students
Git is the de-facto standard for source management and collaboration. Although it is not needed for this course, familiarizing yourself with git will be a valuable skill you will likely use throughout your studies and career. To clone the repository using git, use this command:
git clone https://lab.compute.dtu.dk/cp/02002students.git
Note
If you don’t have git, you can download it from: https://git-scm.com/downloads. Accept the recommended default settings during install (on Linux, run sudo apt install git
)
You should end up with a folder called: 02002students
containing the source code.
You can move the folder to a new location, but once you complete the next step, you may not move or rename the folder for the remainder of the course!. It is important that you remember the location of this folder.
Step 5: Install the course toolbox and software packages#
You need to know the absolute path of the folder for the next step. You can find the absolute location by right-clicking on the folder and selecting Properties (Windows) or Get Info (Mac). The path will be listed under Location (Windows) or Where (Mac).
Open a terminal. If you are not sure how to open a terminal, see the bullet points below:
On windows, press the -key, type
cmd
, and pressEnter
to open the first result.On Mac, press the ⌘-key +
Spacebar
, typeterminal
, and pressEnter
to open the first result.
Navigate to the folder you created in the last step, i.e.
02002students
.You can display the current path of the terminal by typing
cd
(Windows) orpwd
on (Mac/Linux).You change to a subfolder by typing
cd name_of_the_folder
, or move one folder up by typingcd ..
.
Check that you have navigated to the correct folder, by verifying that it contains
requirements.txt
.-You can list which files are in the folder by typing
dir
(Windows) orls
(Mac/Linux).Run the following command in the terminal:
python -m pip install -r requirements.txt
python3 -m pip install -r requirements.txt
python3 -m pip install -r requirements.txt
The command will print a lot of output about the installation process, but assuming the final line looks similar to
Successfully installed bidict-0.22.1 coverage-7.3.0 cp-2023.0 diskcache-5.6.1 dtumathtools-1.1.0 flask-socketio-5.3.5 importnb-2023.1.7 matplotlib-3.6.3 mergedeep-1.3.4 pyfiglet-0.8.post1 python-engineio-4.6.1 python-socketio-5.8.0 sympy-plot-backends-2.4.3 unitgrade-1.0.0.0
you are good to go.