Software and required libraries

angelo.spognardi (4680 points)
37 62 96
asked Sep 24, 2021 in News by angelo.spognardi (4,680 points)

Python distribution used in this course: Anaconda

We use the Anaconda Python distribution. It is available at and contains:

  • Python 3.7 or newer;
  • many standard and useful libraries;
  • the Spyder IDE (Integrated Development Environment), which we use in class and during the exam.

For more details on how to install Anaconda see

NOTICE: when installing Anaconda in Windows, choose the “Only for me” option.

Required/useful libraries

Once you have installed Anaconda, you must/could install these other Anaconda packages

Library Needed for Anaconda Prompt command How to use it
ddt Run tests read from a JSON file conda install -c conda-forge ddt It's imported by the test machinery
pytest-timeout Apply a timeout to each test execution conda install pytest-timeout Adds the new parameter --timeout=<seconds> to the pytest command
stopit Apply a timeout only to your function execution conda install -c conda-forge stopit It's imported by the test machinery
pytest-profiling Examine the time spent in each called function conda install -c conda-forge pytest-profiling Adds the new parameter --profile to the pytest command
Spyder IDE (editor+debugger) conda install spyder
spyder-unittest Run tests from inside Spider conda install -c conda-forge spyder-unittest Adds a new tab to Spyder to run/show tests (choose pytest and the directory)
spyder-line-profiler Examine the execution times from inside Spyder conda install -c conda-forge spyder-line-profiler Adds a new menu command to Spyder to profile the execution times of all functions
radon Compute the “intricacy” of your code
(maximum  cyclomatic complexity)
conda install -c conda-forge radon radon cc -a -s --show-closures
Notepad Write programs. DEPRECATED!!

DO NOT USE IT: it does not properly handle the Unix newline character in text files ('\n')

Notepad++ Write programs.
Wordpad Write programs. Included in Windows
Beyond Compare Very useful file comparator for both text and pictures

To update all Anaconda libraries use the following command from an "Anaconda Prompt" window:

  • conda update --all

Other useful commands

The homework tests are contained in the file. Each one is a method that begins with 'test_' and is automatically discovered and run by pytest.

To run all tests:

  • pytest
  • pytest -v --durations 0                                  # this one lists all the slowest tests

To run a specific test:

  • pytest -v -k <substring of the text name>

For example, pytest -k 2_values -v.

To compute the code “intricacy” (maximum cyclomatic complexity):

  • radon cc -a -s --show-closures

To compute the average test running time (by taking the best of 3 runs and by averaging on 5 executions for each run):

  • python -u -m timeit -v -v -v -v -n 5  -r 3  -s 'from test_01 import Test' 'Test.main()'

To profile your code and understand which part is slower (if you have installed pytest-profiling):

  • pytest -rA -v --profile

NOTICE: to get the 20 slowest times you should modify pytest-profiling as follows:
Change file .../Anaconda/lib/python3.*/site-packages/ such that line 64 is changed to

pstats.Stats(self.combined, stream=terminalreporter).strip_dirs().sort_stats('tottime').print_stats(20)

instead than

pstats.Stats(self.combined, stream=terminalreporter).strip_dirs().sort_stats('cumulative').print_stats(20)


To interactively explore the profiling results you can use snakeviz:

  • install snakeviz (a .prof files visualizer): conda install snakeviz;
  • execute your test with the profiler: pytest --profile;
  • show the execution times with snakeviz: snakeviz prof/;
  • your browser opens on a page that allows you to find where most time has been spent;
  • look for your implemented function (normally named ex1) and click on its header line: the visualization will zoom on it.

Python 4 Android

Choose Python version 3

2 Answers

Quellocinese (2700 points)
2 4 22
answered Sep 29, 2021 by Quellocinese (2,700 points)
It was very helpful and easy to understand, i've set it up with no problems!
Luigi Pizza (6120 points)
11 20 65
answered Sep 30, 2021 by Luigi Pizza (6,120 points)
edited Oct 14, 2021 by Luigi Pizza
Thank you for the instructions, Professor!

P.s. This comment was followed by a question which professor Spognardi answered in his next lecture. Therefore, I was thinking to cancel it, since this comment served its purpose. But I can't really find a way to do that, i can just hide it, what can i do?