If you use the PCs in the computer room, you don’t need to install any software, just configure it. If you want to use your own device, further steps may be necessary depending on your operating system and choice of programming language (Matlab or Python). Below you will find instructions for the recommended setup. You can of course use your own setup, e.g. if you’re already using Spyder instead of Visual Studio Code, but support on my part is limited.
Linux is free and open source software, which aligns well with public research: there is no need for expensive licences and code can be freely shared and developed within the community. Accordingly, most scientific software is written with Linux in mind, and most supercomputers are running Linux.
Wikipedia has a good summary concerning Git:
Git is a distributed version control system that tracks changes in any set of computer files, usually used for coordinating work among programmers who are collaboratively developing source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows (thousands of parallel branches running on different computers).
As an example of how powerful Git is, take a look at the Linux Kernel and the sheer number of commits and contributors.
To install WSL on Windows, open PowerShell or Windows Command Prompt in administrator mode. You can search for this applications by using the search button in the task bar. Right-click on the application and select Run as administrator. Then type the following command in the terminal:
--install wsl
Usually this should install all requirements. If you get an error during installation and you are unsure if you can fix it on your own, you can ask me for support. After running the command, you are required to restart your computer. After the restart and logging in, a terminal should pop up on your screen, which finishes the installation. You are then required to set up a user name (the user name needs to be lower case) and password. Be aware that you are required to set a password – if you leave it empty, you are not able to obtain administrator rights! Now you have a Ubuntu subsystem in your Windows integrated. You can always start an Ubuntu terminal from your task bar.
Additional recommendation: Install Windows Terminal from the Microsoft Store if you use WSL. This terminal is the modern version of the PowerShell. To start Ubuntu from this terminal, open the terminal and execute the command ubuntu
. This command also works in other Windows terminals.
Before you can install Git, your systems should be on the newest version. For Ubuntu in WSL and other Debian derivatives, use the following commands:
sudo apt update
sudo apt full-upgrade
To install Git on Linux/WSL use the following command:
sudo apt install git
There is the possibility that it is already installed. After the installation, you need to set up your user name and your e-mail address. This can get done by using the following commands:
git config --global user.name "Your name"
git config --global user.email "your_email@example.com"
Here you should use your TU Graz e-mail address. If you already have set up Git, and you do not want to overwrite your global settings (because maybe you already use GitHub), you can instead set local configuration in the necessary repositories:
git config --local user.name "Your name"
git config --local user.email "your_email@example.com"
The next step is to create an SSH key. This is required to establish a safe connection between your machine and the TU GitLab server. You can perform the same steps also for e.g. GitHub.
ssh-keygen -t ed25519 -C "your_email@example.com"
You can use the suggested default filename and the passphrase can be empty. This yields output similar to the following:
patrick@earth:~$ ssh-keygen -t ed25519 -C "your_email@example.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/patrick/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/patrick/.ssh/TUGitLab
Your public key has been saved in /home/patrick/.ssh/TUGitLab.pub
The key fingerprint is:
SHA256:pgXN9usOAjqZiWgvwHT8p5cS3uDKn33Fnl8nXN2xMtk your_email@example.com
The key's randomart image is:
+--[ED25519 256]--+
| |
| o |
| . . + . |
| . o o . o =|
|o . o S o + E+|
|oo = = = + .o. |
|+.* o O o + . o..|
|..o. =o= + o ...|
| .+ooo...o .. |
+----[SHA256]-----+
Note: SSH keys are requiered to establish a secure connection between your computer and a remote computer. Do not give your SSH keys to other persons!
The next step is to register this key on your machine. This can be done by the following commands:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
If you set a filename different from the default, e.g. ~/.ssh/TUGitLab
, then WSL might have problems registering the SSH key persistently. In that case, add the following lines to ~/.ssh/config
:
Host gitlab.tugraz.at
IdentityFile ~/.ssh/TUGitLab
The last step to do is to register the SSH key in GitLab. To do so, log in to https://gitlab.tugraz.at/, click on your profile picture in the top left corner and choose Edit profile. Then click on SSH Keys and then on Add new key. In the line key, you need to copy your SSH key which can be found in ~/.ssh/id_ed25519.pub
. To see the content of the file, use the following command:
cat ~/.ssh/id_ed25519.pub
On most Linux systems, you need to use Ctrl+Shift+C
to copy content from the terminal. Then give your key a name, and Git is ready to use.
These steps are only required if you use Matlab on Windows (or if you do not want to use WSL on Windows for Python).
Download the installer from https://git-scm.com/. Execute the installer, use the standard settings, except for the question Configuring the line ending conversions. There you need to switch from Checkout Windows-style, commit Unix-style line endings to Checkout as-is, commit Unix-style endings. On the last page, choose to launch Git Bash. Then you can use the same command as above to create an SSH key. Be aware that the folder structure is different on Windows.
If you want to use Matlab locally, you can obtain a license at https://de.mathworks.com/academia/tah-portal/graz-technische-universitaet-31643617.html, but be aware that Matlab is only officially supported on Windows, macOS, Ubuntu, SLES (SUSE Linux Enterprise Server) and RHEL (Red Hat Enterprise Linux). It is not possible to use the Matlab Tutor in this part of the course, because working with an IDE (integrated development environment) is essential.
If you use Matlab on the PCs in the computer room, you need to switch to a slightly newer version. In the terminal, run the following:
module load matlab/2019b
matlab &
Run the following command in the terminal. These packages are required to be able to install Python packages and for visualization.
sudo apt install python3-pip python3-tk
There are a lot of different IDEs (integrated development environments) available for Python. Popular ones are Spyder, PyCharm and Visual Studio Code. I recommend to use Visual Studio Code, because it has a lot of extensions for different programming languages and is easy to use.
To install Visual Studio Code on Linux, download the *.deb
package from https://code.visualstudio.com/Download. Afterwards, install the *.deb
package with the following command (replace the path to the place you downloaded the *.deb
file):
sudo apt install ./*.deb
For WSL users, download the Windows installer and install VS Code in Windows. It automatically recognizes that there is a WSL distribution available, and asks you if you want to install the WSL extension at the first startup.
Afterwards, you are able to run Visual Studio Code directly from Windows (for WSL Users) or from the Terminal with the command code
(for Linux users). WSL users need to connect to WSL in Visual Studio Code. This can be done with the button in the lower left corner (Open a remote Window). When you press this button, a drop-down menu should pop up, and there you can choose to connect to WSL. To disconnect from WSL, use the same button.
Next, you should install the Python extension. You can also search for this extension in the extensions tab on the left side in Visual Studio Code. Optionally, you can also install the Black formatter.
You can set up a Python Virtual Environment by using the following command, just replace the folder where you want to store it:
python -m venv ~/path_to_new_virtual_environment
Ubuntu requires an additional package when you want to initialize a virtual environment. You will get an error in which it is stated which package you should install. You can then install the package with the following command, where you have to replace the asterisks with the version nummer given in the error message:
sudo apt install python*.**-venv
When the virtual environment is set up, you can use it by activating it with the following command:
source ~/path_to_new_virtual_environment/bin/activate
To deactivate it, use this command:
deactivate
When the virtual environment is active, you can install packages with the following command:
pip install numpy
In this course you are required to install numpy
, matplotlib
, pytest
and scipy
. You can find additional packages on https://pypi.org/.
When the virtual environment is active, you can run a Python file with the following command:
python3 ~/path/to/python/file.py
You can also run a Python file directly from Visual Studio Code. Just open the folder which contains the Python file in Visual Studio Code, open the Python file, and in the lower right corner you have to set the Python Interpreter. A drop down should appear when you press the button. Here you can choose to enter the Python interpreter path. The Python interpreter can be found in the bin
folder of the virtual environment. There are usually three interpreters in this folder called python
, python3
and python*.**
. Any one of them does the job.