def METHOD_NAME(experimentPath, exp, target="PsychoPy"):
    """
    Generate python script from the current builder experiment.
    Parameters
    ----------
    experimentPath: str
        Experiment path and filename
    exp: experiment.Experiment object
        The current PsychoPy experiment object generated using Builder
    target: str
        PsychoPy or PsychoJS - determines whether Python or JS script is generated.
    Returns
    -------
    """
    import logging  # import here not at top of script (or useVersion fails)
    print("Generating {} script...\n".format(target))
    exp.expPath = os.path.abspath(experimentPath)
    if sys.platform == 'win32':  # get name of executable
        pythonExec = sys.executable
    else:
        pythonExec = sys.executable.replace(' ', r'\ ')
    filename = experimentPath
    # compile script from command line using version
    compiler = 'psychopy.scripts.psyexpCompile'
    # if version is not specified then don't touch useVersion at all
    version = exp.settings.params['Use version'].val
    # if useVersion is different to installed version...
    if version not in [None, 'None', '', __version__]:
        # make sure we have a legacy save file
        if not Path(exp.legacyFilename).is_file():
            exp.saveToXML(filename=exp.filename)
        # generate command to run compile from requested version
        cmd = [
            pythonExec, '-m', compiler, str(exp.legacyFilename), '-o', experimentPath
        ]
        # run command
        cmd.extend(['-v', version])
        logging.info(' '.join(cmd))
        output = Popen(cmd,
                       stdout=PIPE,
                       stderr=PIPE,
                       universal_newlines=True)
        stdout, stderr = output.communicate()
        sys.stdout.write(stdout)
        sys.stderr.write(stderr)
        # we got a non-zero error code, raise an error
        if output.returncode != 0:
            raise LegacyScriptError(
                'Error: Script compile exited with code {}. Traceback:\n'
                '{}'.format(output.returncode, stderr))
    else:
        compileScript(infile=exp, version=None, outfile=filename)