Sunday, March 03, 2024

How to fix error: No module named 'apt_pkg' on Ubuntu 18.04

 Ubuntu 18.04 has python3.6.x installed but after install python3.8 and used "update-alternatives" to change the default python3 to python3.8, got the following error when running unknown command on the terminal

$ dummyyycommand  
    from CommandNotFound import CommandNotFound
  File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in
    from CommandNotFound.db.db import SqliteDatabase
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

This is caused because python3.8 cannot load "apt_pkg.cpython-36m-x86_64-linux-gnu.so"

$ cd /usr/lib/python3/dist-packages; ls -al | grep apt
drwxr-xr-x   4 root root   4096 Mar  3 22:23 apt
drwxr-xr-x   4 root root   4096 Jun  1  2021 aptdaemon
-rw-r--r--   1 root root  51576 Dec  1  2022 apt_inst.cpython-36m-x86_64-linux-gnu.so
-rw-r--r--   1 root root    227 Dec  1  2022 apt_inst.pyi
-rw-r--r--   1 root root 346784 Dec  1  2022 apt_pkg.cpython-36m-x86_64-linux-gnu.so
-rw-r--r--   1 root root   8900 Dec  1  2022 apt_pkg.pyi
drwxr-xr-x   3 root root   4096 Mar  3 22:23 aptsources
-rw-r--r--   1 root root    226 Dec  1  2022 python_apt-1.6.6.egg-info

To fix this issue:


To fix this issue just create a link named 'apt_pkg.so' points to "/usr/lib/python3/dist-packages/apt_pkg.cpython-36m-x86_64-linux-gnu.so"

$ cd /usr/lib/python3/dist-packages
$ sudo ln -s apt_pkg.cpython-36m-x86_64-linux-gnu.so  apt_pkg.so

Monday, January 29, 2024

Tmux startup script tempalte

 Tmux script template

#!/bin/bash

SESSION_NAME=dev

# new-session -c start-directory -n window-name -s session-name -t group-name -x width -y height [shell-command]
tmux has-session -t ${SESSION_NAME} 2>&1 >/dev/null

#if [ $? -ne 0 ];then
#	source /opt/.../export.sh
#	tmux new-session -s $SESSION_NAME -n main -d
#	tmux new-window  -c $SRC_DIR -n editor
#	tmux new-window  -c $BUILD_DIR -n build
#	tmux attach -t $SESSION_NAME
#	tmux select-windows -t $SESSION_NAME:0
#else
#	echo "Session is already started"
#fi
#

if [ $? -ne 0 ]; then
    # create new session
    tmux new-session -s ${SESSION_NAME} -n main -d
    tmux split-window -h
    tmux split-window -v
    tmux attach -t ${SESSION_NAME}
else
    echo "Tmux session is already created. Use 'tmux attach -t SESSION_NAME'"
fi

Friday, January 26, 2024

 Just a note.

Original post: CPU performance over time from T420 to T480



Tuesday, August 29, 2023

Convert between pandas DatetimeIndex to Python datetime:

Convert between pandas DatetimeIndex  to Python datetime:

dt_df = df_w.index.to_frame()
dt_series = df_w.index.to_series()

print(dt_df.dtypes)      # --> Date    datetime64[ns]
print(dt_series.dtypes)  # datetime64[ns]


for x in dt_df["Date"]:
    assert isinstance(x, pd.Timestamp)
    d = x.to_pydatetime()
    cw = d.isocalendar().week
    print(f"{d} - cw{cw}")


for x in dt_series:
    assert isinstance(x, pd.Timestamp)
    d = x.to_pydatetime()
    cw = d.isocalendar().week
    print(f"{d} - cw{cw}")

Friday, August 25, 2023

UGREEN M.2 SSD 外付けケース Windows 10で認識しない

UGREEN M.2 SSD 外付けケース 

  • NVME/SATA 両対応
  • USB 3.2 Gen2規格
  • UASP/TRIM対応
  • 10Gbps高速転送
  • 2230/2242/2260/2280 M key/B+M key SSD対応


上記の外付けSSDを買ったがWindows 10のPCで最初は認識されたが,あるタイミングで何らかの不具合(Blue screenやDisk access error)が発生して認識できなくなった.

いろいろ調べた結果 認識できなかったPC(HP Zbook 15 G3)では,Device ManagerのStorage controllerで”USB Attached SCSI (UAS) Mass Storage Device”がこの問題と関係がありそうだ・・・(ここに似た問題が報告されている).HPのサポートサイトに載っている重要なドライバ更新プログラムやSSD関連のドライバをアップデートしたら認識されるようになって動作も安定になった.