I am using a different bitcoin library. This prints address and hash160 from a private key:
from bitcoinutils.setup import setup
from bitcoinutils.keys import P2pkhAddress, PrivateKey, PublicKey
# setup the network
# provide a private WIF key
priv = PrivateKey.from_wif('...
The base58.b58decode and base58.b58encode functions only do the Base 58 decode/encode. However xpubs are encoded with Base 58 Check encoding. The difference is that Base 58 Check encoding computes a checksum of the payload and appends the first 4 bytes of that to the payload before the base 58 encoding.
You need to be using base58.b58decode_check and base58....