Julia – AttributeError(“’PyCall.jlwrap’ object has no attribute ‘encode’”)

Solution for Julia – AttributeError(“’PyCall.jlwrap’ object has no attribute ‘encode’”)
is Given Below:

I am trying to use the package mappy from python inside julia but I get this error: AttributeError(“‘PyCall.jlwrap’ object has no attribute ‘encode'”). I don’t understand this error.

here is my code:

using PyCall
using FASTX
using CodecZlib

import mappy as mp

def aligner(name,preset,threads):
    aligner = mp.Aligner(name,preset=preset,n_threads = threads)
    return aligner

def mappy(seq,aligner):
        line = next(aligner.map(seq))
        return False
    except StopIteration:
        return True
aligner = py"aligner"("genome.idx","sr",4)
for record in FASTQ.Reader(GzipDecompressorStream(open("data_file.fastq.gz")))
    check = py"mappy"(sequence(record),aligner)

The problem was with the data type send to mappy. The sequence(record) is not a string type so It wasn’t able to process the data. I don’t know why the error returning is this weird one. The corrected code should be:

for record in FASTQ.Reader(GzipDecompressorStream(open("data_file.fastq.gz")))
    seq = string(sequence(record))
    check = py"mappy"(seq,aligner)