Categories
python ubuntu

How to build python 3 from source on Ubuntu 22.04?

Install pre-requisites sudo apt install build-essential libssl-dev libffi-dev software-properties-common libbz2-dev libncurses-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev libgdbm-compat-dev libreadline-dev Download the python version you want from https://www.python.org/downloads/source/ cd /opt sudo wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tar.xz Extract the downloaded source sudo tar -xvf Python-3.9.16.tar.xz Read the info cd Python-3.9.16/ cat README.rst Compile and Install python ./configure make When running make […]

Categories
python

Ubuntu 22.04 + Firefox + Selenium + Geckodriver: Connection refused

The Ubuntu 22.04 + Firefox with Selenium and Geckodriver problem is: selenium.common.exceptions.TimeoutException: Message: Connection refused (os error 111) An older firefox version was installed from source after looking at geckodriver’s supported platforms docs… Environment details: $ firefox –version Mozilla Firefox 89.0.2 $ geckodriver –version geckodriver 0.29.1 (970ef713fe58 2021-04-08 23:34 +0200) selenium 3.14.1 Example script: from […]

Categories
python

Python Performance: Checking a collection contains a value (Membership)

A common task in programming and development is finding items that exist already or recognising duplicates. This is done by checking membership of an element in a collection. Often a list is used as it is mutable (can be changed and items added to it) and it is suited for single items. However there are […]

Categories
python

Python ModuleNotFoundError

One of the classic problems when running a python script that imports another module is not being able to find the module. ModuleNotFoundError: No module named ‘xxx’ There are 2 fundamentals to remember. A python module is – simply – a file A Python package is a folder containing a __init__.py file. A folder of […]

Categories
python

Python: Check how long a HTTPX Request took to run?

To check the response time of a python httpx request, use the response.elapsed attribute. import httpx client = httpx.Client() response = client.get(‘https://stoicquotesapi.com/v1/api/quotes/random’) print(response.elapsed.total_seconds()) This will print out the response time: 1.334806 Again: response.elapsed.total_seconds())