Pre-course material
Before the course we require you to follow the following steps to ensure you have all programs installed before coming to the course. We require you to have a computer you can use for the practical exercises. If possible, try to get an extra screen, so you can both view the presentation and try it out on your own at the same time.
It is important to come prepared before the first lecture, in order to fully take advantage of the hands-on exercises, coming at a rather high pace.
Note: On Friday the 6th of October at 13:00 there will be a session for helping students with the installation of the software. Please make sure to attend the session in case you have not been able to setup your working environment.
We have the 5 following requirements:
- Install Python on your machine
- Install dependencies on your machine
- Make sure you have a proper text editor
- Check that the installation went fine, by running a given simple script
- Download all files Links to an external site. and scripts needed for the course
Throughout the course, we will use the terminal to run scripts, open files etc. If you are unfamiliar with this, consider looking at this tutorial Links to an external site. to learn how to open a terminal and how to use it. A cheat sheet with the most useful commands can be found here Links to an external site. for Linux/Unix/Mac users, and here Links to an external site. for Windows users.
To open the terminal
For Windows
After installing anaconda (described in the next section), press the windows button and search anaconda
. The terminal should appear in the search results; click on it and a new terminal window will open up.
For Mac
Press command
and space
simultaneously. In the new window type terminal
, select the terminal from the list and press `enter`. A new terminal window will open up.
For Linux
Press control
, alt
and t
simultaneously. A new terminal window will open up.
We provide two different ways for setting up your system. If you are new to python, we recommend following the first way, using conda, since the installation is easier. If you have experience with Python and/or feel comfortable with the terminal and installing packages manually, you may use the second guide.
Feel free to select the option that seems easier for you!
Note that throughout these guides we use the black boxes to signify the terminal and everything starting with the symbol $ should be executed using it.
Guide 1
1. Installing packages using Conda
The first guide includes the installation of Anaconda Links to an external site. and the creation of an environment containing all the required packages, as well as the Spyder IDE. Anaconda is a very convenient package and environment manager not just for this course. It allows for creation of environments that are isolated from the rest of your system, containing all the required packages for a project and keeping track of dependencies between them. That feature can be very useful when you want to reproduce results that have been created using specific software.
Start by downloading and installing Anaconda Links to an external site. if you don’t already have it installed. Or download conda, which is a more lightweight version of Anaconda. You can read more about the difference here Links to an external site.. Anaconda is the easiest way to download and manage your python libraries.
For Windows
Download this conda environment file containing all the required software for the course in your preferred location. Open up the Anaconda terminal, navigate to the folder where the environment file is downloaded and run
$ conda env create -f environment-win.yml
This step might take some time. When the installation is finished, you should be able to see the instructions for activating the environment in the terminal. To activate the environment with the installed packages run
$ conda activate workshop
You can also open the Spyder IDE using the command
$ spyder
Note 1: You need to activate the environment every time you open a new terminal window.
Note 2: The environment also contains the Spyder IDE presented later in this guide. If you don't want to install it, open the environment file and remove the specific line (line 9 in the environment-win.yaml file). Other recommendations for text editors and IDEs can be found in the section Using a proper Text Editor.
For Linux/MacOS
Download this conda environment file containing all the required software for the course in your preferred location. Open up the terminal, navigate to the folder where the environment file is downloaded and run
$ conda env create -f environment-mac.yml
This step might take some time. When the installation is finished, you should be able to see the instructions for activating the environment in the terminal. To activate the environment with the installed packages run
$ conda activate workshop
You can also open the Spyder IDE using the command
$ spyder
Note 1: You need to activate the environment every time you close the terminal window you are using.
Note 2: The environment also contains the Spyder IDE presented later in this guide. If you don't want to install it, open the environment file and remove the specific line (line 9 in the environment-mac.yaml file). Other recommendations for text editors and IDEs can be found in the section Using a proper Text Editor.
2. Testing your installation
All operating systems (Windows, Linux, MacOS)
After you have finished with the creation of the environment and have activated it (as shown in the previous step), use your terminal to check the Python version. Type
$ python --version
and make sure the Python version is correct, or start the python interpretor
$ python
If you decided to start the interpretor, exit it using
$ quit()
Running a test script
Download this test script or get it by downloading the zip archive with all the files needed for the course from here. Links to an external site.Navigate to the location where the files was downloaded and run
$ python test.py
If this works fine, you should see the current time printed with “big digits”
3. Tips
This sections contains some useful tips for using the conda environment created above and it is applicable to all operating systems.
Conda
To activate an environment run
$ conda activate <environment_name>
To deactive the current environment run
$ conda deactivate
To see a list of the available environments run
$ conda env list
To remove an environment run
$ conda env remove --name <environment_name>
A more detailed list of the available commands can be found in the conda documentation Links to an external site. or the conda cheat sheet Links to an external site..
Spyder
To run the Spyder IDE installed in the environment run
$ spyder
This will "freeze" your terminal until you exit spyder. If you want to run spyder in the background, so that you can use the specific terminal window, instead run
$ spyder&
Detailed documentation about spyder can be found in the website of the project Links to an external site..
Jupyter
In the course, we will write Python code as standalone files. However, during the lecture, we will also use Jupyter Notebook. Jupyter Links to an external site. is a web-based tool which allows us to evaluate our code line by line. The Jupyter files are called notebooks Links to an external site. and will serve a single purpose in this course: a quick demonstration of Python code. The environment created above contains Jupyter and you can run it using
$ jupyter notebook
This will "freeze" your terminal until you exit jupyter. If you want to run jupyter in the background, so that you can use the specific terminal window, instead run
$ jupyter notebook&
Any of the two commands above will open up a new tab in your preferred browser, containing the files of the current folder. There you can create a new notebook and experiment with python code. For a more detailed introduction to jupyter visit the read-the-docs documentation page Links to an external site..
4. Download files and scripts
We will be using a number of files and scrips during this course, which are all downloadable by clicking this link Links to an external site.. If we update any scripts closer to the course, you might be required to download this material again to get the latest versions of everything.
For Windows
Right click on the downloaded file and select Extract Here to unzip it. A new folder with the same name should be created in the current location, containing all the required files.
If you don't have that option (or any other extraction option) you can download and install 7zip Links to an external site., which is used for packing and unpacking files.
For MacOS
Double click on the downloaded file to unzip it. A new folder with the same name should be created in the current location, containing all the required files.
For Linux
Right click on the downloaded file and select Extract Here to unzip it. A new folder with the same name should be created in the current location, containing all the required files.
Guide 2
This guide describes the installation of Python and the required packages manually. Follow this guide if you feel comfortable with Python and/or terminal.
1. How to install Python
Please, choose to install the version 3.9
or above. The latest version available is 3.10.4
On Windows
Here are the installation steps on Windows Links to an external site.. The installer should look like this, with the version you chose for the installation:
On Mac OS X
Since Mac OS X 10.8, Python 2.7 is pre-installed by Apple. This is an incompatible version with this course. You should instead download the installer Links to an external site. for the version 3.9 or higher, double-click and follow the instructions.
More information can be found on docs.python.org/3.9 Links to an external site.
IMPORTANT NOTE: If you are not interested in a system-wide version of Python3, you can use pyenv
to easily switch between multiple versions of Python. You can install pyenv from GitHub
Links to an external site.. After installation, you can install version 3.9 by issuing the following command in your Terminal.
$ pyenv install 3.9
On Linux/Unix
Using a package manager (recommended)
Install Python3 and pip using your package manager. For Ubuntu and Debian, it goes like this:
$ sudo apt-get update
$ sudo apt-get install python3 python3-pip
Installing from source
You can also install Python from source Links to an external site..
A note for Linux/Unix and Mac users
The command to run Python is python3
. If you wish to be able to start Python by typing just python
, add the following line to the file ~/.bashrc
(or ~/.bash_profile
):
alias python=python3
2. How to install dependencies
Later in the course we will try out pandas
and some plotting, so before that we have to download those dependencies.
For Windows
Start by downloading and installing Anaconda Links to an external site. if you don’t already have it installed. Or download conda, which is a more lightweight version of Anaconda. You can read more about the difference here Links to an external site.. Anaconda is the easiest way to download and manage your python libraries.
Once you have downloaded Anaconda you can open up the Anaconda terminal, and from there use pip
to install the following:
$ pip install pyreadline
$ pip install pandas
$ pip install matplotlib
pyreadline
is a library specifically needed for Windows users, and is not required for Mac or Linux.
For Mac Os X and Unix/Linux users
To install the dependencies in unix-based systems use pip to install Jupyter (see below for more details), Biopython and other libraries that will be needed during the course:
$ pip3 install --user jupyter
$ pip3 install --user biopython
$ pip3 install --user pandas
$ pip3 install --user matplotlib
3. Using a proper Text Editor
We are going to type (a lot of) Python code, so you’d better have a good text editor. This is useful for several reasons: The text editor can highlight the Python keywords and handles the particulars regarding tabulations (which we will introduce in the course).
Emacs or Vim
are probably the best text editors, albeit for tech-savvy people.
Sublime or Atom
If you are not the latter kind, Sublime Text Links to an external site. or Atom Links to an external site. are excellent cross-platform alternative. You should probably customize it to your taste first.
PyCharm
Another alternative is PyCharm Links to an external site. , an IDE (Integrated Development Environment) for python. In addition to being an editor for python code (with code completion/inspection, syntax highlighting etc.) it comes with a terminal, python console, git and conda integration and more. Go ahead, install the free version Links to an external site. and give it a try!
Spyder
Finally, Spyder Links to an external site. is another an IDE (Integrated Development Environment) for python, promoted as a scientific development environment for Python. In addition to the standard features of IDEs (such as code completion and syntax highlighting) it contains a variables explorer, allowing for inspection and interaction with the variables created during the execution. This IDE is quite similar to the R Studio and the installation is very easy using the installer Links to an external site. or through conda (see conda environment files).
4. Testing your installation
After you have finished with the installation of the required packages, use your terminal to check the Python version. Type
$ python3 --version
and make sure the Python version is correct, or start the python interpretor
$ python3
If you decided to start the interpretor, exit it using
$ quit()
Running a test script
Download this test script or get it by downloading the zip archive with all the files needed for the course from here. Links to an external site.Navigate to the location where the files was downloaded and run
$ python3 test.py
If this works fine, you should see the current time printed with “big digits”
Jupyter notebooks Links to an external site.
In the course, we will write Python code as standalone files. However, during the lecture, we will also use Jupyter Notebook. Jupyter Links to an external site. is a web-based tool which allows us to evaluate our code line by line. The Jupyter files are called notebooks Links to an external site. and will serve a single purpose in this course: a quick demonstration of Python code. It is therefore convenient, though optional, to install Jupyter Links to an external site. in advance.
5. Download files and scripts
We will be using a number of files and scrips during this course, which are all downloadable by clicking this link Links to an external site.. If we update any scripts closer to the course, you might be required to download this material again to get the latest versions of everything.
For Windows
Right click on the downloaded file and select Extract Here to unzip it. A new folder with the same name should be created in the current location, containing all the required files.
If you don't have that option (or any other extraction option) you can download and install 7zip Links to an external site., which is used for packing and unpacking files.
For MacOS
Double click on the downloaded file to unzip it. A new folder with the same name should be created in the current location, containing all the required files.
For Linux
Right click on the downloaded file and select Extract Here to unzip it. A new folder with the same name should be created in the current location, containing all the required files.
Impatient about the first lecture? Links to an external site.
Whet your appetite on the Python tutorial Links to an external site. or an informal introduction to Python Links to an external site..