This code works for a file myfile which fits in RAM:
myfile
import Crypto.Random, Crypto.Cipher.AES # pip install pycryptodome nonce = Crypto.Random.