0%

If you are using cv2 or opencv-python and then building the application through docker you will get an importerror: libgl.so.1: cannot open shared object file: no such file or directory.

The best solution is to install the - headless package

headless package does not have GUI dependencies, therefore it reduces the container image size.

1
2
pip uninstall opencv-python
pip install opencv-python-headless

Reference

[Solved] Importerror: libgl.so.1: cannot open shared object file: no such file or directory

1
2
3
4
5
6
7
8
9
import os
os.environ.update(OMP_NUM_THREADS="1",
OPENBLAS_NUM_THREADS="1",
MKL_NUM_THREADS="1",
VECLIB_MAXIMUM_THREADS='1',
NUMEXPR_NUM_THREADS="1")
import numpy as np
import cv2
cv2.setNumThreads(1)

Install FreeRDP

1
sudo apt install freerdp2-x11

Usage

1
2
3
xfreerdp /v:windows_ip:windows_port /u:username /w:1366 /h:768 /bpp:32 \
/network:auto +clipboard +fonts +window-drag \
/a:drive,home,/home/name/share

More

1
Usage: xfreerdp [file] [options] [/v:<server>[:port]]
Read more »

Sometimes, we need to get consistent sorting results like the file browser. At this time, natsort can be used.

Install

1
pip install natsort

Usage

sort lists “naturally”

“naturally” is rather ill-defined, but in general it means sorting based on meaning and not computer code point

1
2
3
>>> a = ['2 ft 7 in', '1 ft 5 in', '10 ft 2 in', '2 ft 11 in', '7 ft 6 in']
>>> sorted(a)
['1 ft 5 in', '10 ft 2 in', '2 ft 11 in', '2 ft 7 in', '7 ft 6 in']
1
2
3
4
>>> from natsort import natsorted
>>> a = ['2 ft 7 in', '1 ft 5 in', '10 ft 2 in', '2 ft 11 in', '7 ft 6 in']
>>> natsorted(a)
['1 ft 5 in', '2 ft 7 in', '2 ft 11 in', '7 ft 6 in', '10 ft 2 in']

Sort Paths Like Windows Explorer

Read more »

replace

str.``replace(old, new[, count])

1
2
3
4
5
>>> msg='For many different, reasons.'
>>> msg.replace('n', '')
'For may differet, reasos.'
>>> msg.replace('n', '', 1)
'For may different, reasons.'

regular expression

re.``sub(pattern, repl, string, count=0, flags=0)

1
2
3
4
5
>>> msg='For many different, reasons.'
>>> re.sub('n', '', msg)
'For may differet, reasos.'
>>> re.sub('n', '', msg, 1)
'For may different, reasons.'
1
2
3
>>> msg='For many different, reasons.'
>>> re.sub('(many|reason)', 'tu', msg)
'For tu different, tus.'

maketrans

Read more »