Ubuntu 16.04 – Fix ‘No Module Named uaclient’ During `sudo apt upgrade`

16.04aptpythonupgrade

I'm trying to upgrade my desktop from ubuntu 16.04 to 18.04.
(I regret not having upgraded it earlier before the ubuntu 16.04 EOL arrived. Two weeks ago I have upgraded two 16.04 notebooks to 18.04 though eventhough it was after the EOL, at that time there was just small problems I could solve).
I did sudo apt update but I'm getting the error below during apt upgrade after that.

ckim@chan-ubuntu:~/prj/abdsn$ sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  cpp-5-aarch64-linux-gnu cpp-aarch64-linux-gnu cuda-command-line-tools-10-0 cuda-compiler-10-0 cuda-cublas-10-0 cuda-cublas-dev-10-0 cuda-cudart-10-0
  cuda-cudart-dev-10-0 cuda-cufft-10-0 cuda-cufft-dev-10-0 cuda-cuobjdump-10-0 cuda-cupti-10-0 cuda-curand-10-0 cuda-curand-dev-10-0 cuda-cusolver-10-0
  cuda-cusolver-dev-10-0 cuda-cusparse-10-0 cuda-cusparse-dev-10-0 cuda-documentation-10-0 cuda-driver-dev-10-0 cuda-gdb-10-0
  cuda-gpu-library-advisor-10-0 cuda-libraries-10-0 cuda-libraries-dev-10-0 cuda-license-10-0 cuda-memcheck-10-0 cuda-misc-headers-10-0 cuda-npp-10-0
  cuda-npp-dev-10-0 cuda-nsight-10-0 cuda-nsight-compute-10-0 cuda-nvcc-10-0 cuda-nvdisasm-10-0 cuda-nvgraph-10-0 cuda-nvgraph-dev-10-0 cuda-nvjpeg-10-0
  cuda-nvjpeg-dev-10-0 cuda-nvml-dev-10-0 cuda-nvprof-10-0 cuda-nvprune-10-0 cuda-nvrtc-10-0 cuda-nvrtc-dev-10-0 cuda-nvtx-10-0 cuda-nvvp-10-0
  cuda-samples-10-0 cuda-toolkit-10-0 cuda-tools-10-0 cuda-visual-tools-10-0 gcc-5-aarch64-linux-gnu-base gcc-5-cross-base libasan2-arm64-cross
  libatomic1-arm64-cross libc6-arm64-cross libc6-dev-arm64-cross libclang1-3.6 libgcc-5-dev-arm64-cross libgcc1-arm64-cross libgomp1-arm64-cross libgsoap8
  libitm1-arm64-cross libllvm3.6v5 libnunit-cil-dev libnunit-console-runner2.6.3-cil libnunit-core-interfaces2.6.3-cil libnunit-core2.6.3-cil
  libnunit-framework2.6.3-cil libnunit-mocks2.6.3-cil libnunit-util2.6.3-cil libpng16-16 libpython-dbg libpython2.7-dbg libstdc++-5-dev-arm64-cross
  libstdc++6-arm64-cross libubsan0-arm64-cross libvncserver1 libxmu-dev libxmu-headers linux-libc-dev-arm64-cross python-dbg python-kerberos python2.7-dbg
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] 
Setting up ubuntu-advantage-tools (27.0~16.04.1) ...
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'uaclient'
dpkg: error processing package ubuntu-advantage-tools (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 ubuntu-advantage-tools
E: Sub-process /usr/bin/dpkg returned an error code (1)

The command python is linked to python2.7 and python3 is linked to python3.5 using alternative system.(update-alternatives). What can I do next?

ADD :
I saw somewhere I have to reinstall opca-client so did this,

ckim@chan-ubuntu:~$ sudo pip3 install --upgrade opcua-client

and then I saw a warning about pip version, so I did
sudo pip install –upgrade pip
and then
sudo pip3 install –upgrade opcua-client
but now see this error below :

....
Do you want to continue? [Y/n] 
Setting up ubuntu-advantage-tools (27.0~16.04.1) ...
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'uaclient.entitlements'
dpkg: error processing package ubuntu-advantage-tools (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 ubuntu-advantage-tools
E: Sub-process /usr/bin/dpkg returned an error code (1)

Best Answer

For me, the reason to cause this problem is that I have additional python distribution installed on my computer /usr/local/bin/python3, which comes before /usr/bin/python3 in the search path. I modified manually the post-installation and pre-remove script in /var/lib/dpkg/info/ubuntu-advantage-tools.postinst and /var/lib/dpkg/info/ubuntu-advantage-tools.prerm and replace python3 with the complete path /usr/bin/python3. This solved my problem.

Related Question