Sunday, September 5, 2021

Fixing "ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory" in Ubuntu 18.04

 If you're using Nvidia CUDA 10.1.243 in your software development, either directly or indirectly and encountered: "ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory", it's caused by incorrect location of the said library. Nvidia have moved the location of the library form cuda-10.1 direcctory to cuda-10.2 directory. I know, this is rather insane. But it is what it is in Ubuntu 18.04, if you installed Cuda from Nvidia's *.deb package. 

The FIX: 

Add the path to cuda-10.2 library into your LD_LIBRARY_PATH, akin to this explanation in stackoverflow: https://stackoverflow.com/questions/55224016/importerror-libcublas-so-10-0-cannot-open-shared-object-file-no-such-file-or/64472380#64472380, i.e. add this line to your shell init file (*.profile or similar ones):

export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} 
The line above assumes you've installed Cuda in its default installation location, i.e. /usr/local. You need to modify this value if you installed Cuda in non-default location.  

Monday, September 14, 2020

Fixing: "matplotlib error - no module named tkinter" in Windows 10

If you are using python 3.x in Windows 10 and encoutered this error: "matplotlib error - no module named tkinter", it's very possible that you didn't install the Tcl/Tk module when installing Python to your machine. The tkinter module comes from Tcl/Tk. Fear not, you don't need to uninstall and reinstall Python to fix it. You only need to modify your Python installation to install the missing Tcl/Tk support as follows:

  1. Go to Add/Remove Programs from Windows 10 search box. From there, select your Python installation, like this: 

  2. Then click the option to modify the Python installation. You'll be presented with this dialog: 

  3. Then click on the Modify option in the Python installer dialog. In the Optional Features dialog that shows up, make sure you checked the tcl/tk and IDLE option, like this (inside the red box): 

  4. Next, just follow the instruction after clicking on the Next button to apply the changes.  
After this, the matplotlib error should be fixed as the tkinter python module is installed. 

Note that even if you install the tcl/tk library via pip install successfully when encountering the matplotlib error, you will probably still left with the same matplotlib error. I'm not sure why it happened in my system. It's probably the module search path is somehow not working properly unless you do a "user/account-wide" or system-wide installation for the module to make it work. In any case, the solution above fixed the error in all cases that I have tested. I think it should work for you too. 

Monday, September 7, 2020

Removing "Still" Frames from Video Files with Ffmpeg

 Ffmpeg is a very versatile tool for video pre-processing and post-processing. One of its most useful feature is removing frames which doesn't have a lot of changes in it, i.e. relatively static background. The parameter to use for this purposes is the mpdecimate flag, the presentation timeframe (setpts)flag might also be used for synchronization purposes. In my case, the command I used to throwaway the relatively static vidio frames as follows:

ffmpeg -i input_vid.mp4 -vf mpdecimate,setpts=N/FRAME_RATE/TB output_vid.mp4

Details about the mpdecimate flag can be read over at: https://ffmpeg.org/ffmpeg-filters.html#decimate-1, and details about the setpts parameter is at https://ffmpeg.org/ffmpeg-filters.html#toc-setpts_002c-asetpts. Hopefully, this is helpful for you.

Sunday, August 23, 2020

Implementing C struct-like Data Structure in Python (Requires Python 3.6+)

 The solution to implement C struct-like data structure in Python is explained in: https://stackoverflow.com/questions/35988/c-like-structures-in-python. You need the presence of dataclass python class to create a syntactically and semantically similar data structure to C struct. This class is implemented in Python 3.7. Therefore, python 3.7 is the lowest version of python supported. However, the support has been backported to Python version 3.6 (see: https://pypi.org/project/dataclasses/#description ). 

Perhaps, you might ask, why not just use Python collections namedtuple data type. Well, namedtuple is syntactically similar to C struct. However, it's immutable, meaning: once you have set its value, you cannot change the value. The only way to change the object value is by creating a new object with the same type and setting the value into different value.

Anyway, this is a sample usage of dataclass:  

as you can see in the screenshot above, the value of c_struc class instance can be changed (mutable), as in a C struct.