How to fix install?

] <> sudo apt upgrade
Calculating upgrade… Error!
The following packages were automatically installed and are no longer required:
liblbfgsb0 libopencv-features2d406t64 libopencv-imgproc406t64 libopencv-shape406t64 libopencv-videoio406t64
libopencv-calib3d406t64 libopencv-flann406t64 libopencv-ml406t64 libopencv-stitching406t64 libopencv-videostab406t64
libopencv-contrib406t64 libopencv-highgui406t64 libopencv-objdetect406t64 libopencv-superres406t64 libopencv-viz406t64
libopencv-dnn406t64 libopencv-imgcodecs406t64 libopencv-photo406t64 libopencv-video406t64 libopencv406-jni
Use ‘sudo apt autoremove’ to remove them.
Not upgrading:
gnustep-base-common gnustep-common libapache2-mod-php php php-mysql strongswan vokoscreen-ng
gnustep-base-runtime imagemagick-7-common libvtk9.3 php-common qterminal unar
Summary:
Upgrading: 0, Installing: 0, Removing: 0, Not Upgrading: 13
473 not fully installed or removed.
Space needed: 0 B / 840 GB available
Continue? [Y/n] Y
Setting up libopencv-shape-dev:amd64 (4.10.0+dfsg-5) …
Setting up python3-pastescript (3.7.0-1) …
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/paste/script/pycache: FileNotFoundError(2, ‘No such file or directory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/paste/script/paster-templates/basic_package/+package+/pycache: FileNotFoundError(2, ‘No such file or directory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/paste/script/util/pycache: FileNotFoundError(2, ‘No such file or directory’)

First thing I would do is:

Then, try the upgrade again.

: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/pymssql/pycache: FileNotFoundError(2, ‘No such file or directory’)
[Errno 2] No such file or directory: ‘/usr/lib/python3/dist-packages/pymssql/exceptions.py’[Errno 2] No such file or directory: '/usr/lib/python3/di
st-packages/pymssql/init.py’dpkg: error processing package python3-pymssql (–configure):
installed python3-pymssql package post-installation script subprocess returned error exit status 1
Setting up initramfs-tools (0.147) …
update-initramfs: deferring update (trigger activated)
Setting up postgresql-client-17 (17.4-1+b1) …
/var/lib/dpkg/info/postgresql-client-17.postinst: 7: .: cannot open /usr/share/postgresql-common/maintscripts-functions: No such file
dpkg: error processing package postgresql-client-17 (–configure):
installed postgresql-client-17 package post-installation script subprocess returned error exit status 2
Setting up mitmproxy (11.1.3-0kali1) …
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/examples/addons/pycache: FileNotFoundError(2, ‘No such file or directo
ry’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/examples/contrib/pycache: FileNotFoundError(2, ‘No such file or direct
ory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/examples/contrib/webscanner_helper/pycache: FileNotFoundError(2, ‘No s
uch file or directory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/pycache: FileNotFoundError(2, ‘No such file or directory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/addons/pycache: FileNotFoundError(2, ‘No such file or direct
ory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/addons/onboardingapp/pycache: FileNotFoundError(2, ‘No such
file or directory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/contentviews/pycache: FileNotFoundError(2, ‘No such file or
directory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/contentviews/image/pycache: FileNotFoundError(2, ‘No such fi
le or directory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/contrib/pycache: FileNotFoundError(2, ‘No such file or direc
tory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/contrib/click/pycache: FileNotFoundError(2, ‘No such file or
directory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/contrib/kaitaistruct/pycache: FileNotFoundError(2, ‘No such
file or directory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/contrib/wbxml/pycache: FileNotFoundError(2, ‘No such file or
directory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/coretypes/pycache: FileNotFoundError(2, ‘No such file or dir
ectory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/io/pycache: FileNotFoundError(2, ‘No such file or directory’
)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/net/pycache: FileNotFoundError(2, 'No such file or directory
')
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/net/dns/pycache: FileNotFoundError(2, ‘No such file or direc
tory’)
E: py3compile:216: cannot create directory /usr/lib/python3/dist-packages/mitmproxy/net/http/pycache: FileNotFoundError(2, ‘No such file or dire
ctory’)
E: py3compile:216: cannot create directory /usr/lib/py

Package samba-common-bin is not configured yet.

dpkg: error processing package samba (–configure):
dependency problems - leaving unconfigured
dpkg: too many errors, stopping
Processing triggers for initramfs-tools (0.147) …
update-initramfs: Generating /boot/initrd.img-6.12.13-amd64
/usr/sbin/mkinitramfs: 127: /usr/lib/dracut/dracut-install: not found
/usr/sbin/mkinitramfs: 127: /usr/lib/dracut/dracut-install: not found
/usr/sbin/mkinitramfs: 127: /usr/lib/dracut/dracut-install: not found
/usr/sbin/mkinitramfs: 127: /usr/lib/dracut/dracut-install: not found
update-initramfs: failed for /boot/initrd.img-6.12.13-amd64 with 127.
dpkg: error processing package initramfs-tools (–configure):
installed initramfs-tools package post-installation script subprocess returned error exit status 127
dpkg: too many errors, stopping
Errors were encountered while processing:
python3-pastescript
python3-gnupg
python3-pymssql
postgresql-client-17
mitmproxy
meson
samba-common
python3-gevent
wifite
python3-cupshelpers
nfs-common
mariadb-server
mariadb-plugin-provider-bzip2
mariadb-plugin-provider-lzma
python3-pycurl
notus-scanner
python3-gssapi
python3-pandas
python3-gpg
system-config-printer
python3-jsonschema
python3-pooch
python3-ipython
python3-twisted
python3-git
python3-gi
wfuzz
python3-flask-limiter
bloodhound.py
python3-bottleneck
faraday
python3-psycopg
python3-psycopg2
legion
python3-numexpr
pgcli
smbclient
python3-pyinstaller-hooks-contrib
python3-pygame
samba-common-bin
python3-lxml:amd64
mariadb-plugin-provider-lzo
gvmd
ipython3
python3-autobahn
python3-paramiko
python3-ibus-1.0
python3-gi-cairo
python3-dnf
samba
initramfs-tools
Processing was halted because there were too many errors.
Error: Sub-process /usr/bin/dpkg returned an error code (1)
I fully upgraded my kali linux version but this happened, how do I solve it

Is this a virtual machine or a host-install?

To fully update the system you run these commands;

sudo apt update
sudo apt full-upgrade -y

apt update is needed to synch the repo with the latest packages

apt upgrade will not upgrade the system properly, it has to be ‘full-upgrade’ this is written in the Kali docs

as for the python error, have you used the pipx python install?
I ask because pycache errors can often be caused by this, as pipx installs files locally to folders, not globally to the system, so unless you supply a path to the python file, it doesn’t know where to find it.

no virtual,host install

still the same no change

I don’t think it was meant as a solution, just a correction of something another person here advised to do wrongly.

If I had to guess, I’d say you previously installed some tools from outside the kali repositories and ignored warnings about incompatibilities, thus resulting in this unstable state right now.

If that’s the case, either carefully and meticulously undo what you did before, if you still have log files about it - or install kali anew.

Traceback (most recent call last):
File “/usr/bin/debtags”, line 32, in
from debian import deb822
ModuleNotFoundError: No module named ‘debian’
13 packages can be upgraded. Run ‘apt list --upgradable’ to see them.
how to fix?

As I already told you - this is not a simple case of “enter that command and everything is fine”.

If my assumption is correct, then this is on you, and i gave you options.

At this point, I think it would be quicker to do a reinstall.