From the code snippet you've provided, it looks like you're trying to encode a Python Image (from PIL or related?) to PNG bytes, and then load those into an NSImage. To do this literal operation, you'd need to get the bytes contained within the MemoryView instance, create a Swift Data instance from them, and then use NSImage(data:) to initialize an NSImage from those bytes.
However, going to and from a PNG representation might not be the fastest way to perform this conversion. You may want to start from the raw bytes of your image and create an NSImage from that (via
CGImage), which will save on the intermediate step.
Sorry for being a little vague about this, because depending on what exactly you're attempting there are possibly multiple other paths to accomplish this with various performance and memory usage characteristics.