Run Sen2Cor from python program

I’m trying to call Sen2Cor in a python file using this code:

subprocess.check_call([L2A_Process , str(scene)],shell=True)

where L2A_Process is the path for L2A_Process bash script and scene is the path for the SAFE folder. However, on running this file, it says

Sen2Cor/bin/python2.7: not found

However, The following code returns a positive output and affirms that the file is there:

if os.path.exists("/usr/local/lib/python2.7/dist-packages/Sen2Cor/bin/python2.7"): logging.info("Sen2Cor/bin/python2.7 exists") else: logging.info("Sen2Cor/bin/python2.7 does not exist")

I’ve also tried testing with absolute paths but to no avail

Any clue about what might help?

try add this
env_os = os.environ
env_os[“PATH”] = “/Sen2Cor-02.05.05-Linux64/bin:" +
env_os[“PATH”]
sen_env = {
“SEN2COR_HOME”: "/
/sen2cor/2.5”,
“SEN2COR_BIN”: “/usr/local/Sen2Cor-02.05.05-Linux64/lib/python2.7/site-packages/sen2cor”,
“LC_NUMERIC”: “C”,
“GDAL_DATA”: “/usr/local/Sen2Cor-02.05.05-Linux64/share/gdal”,
“GDAL_DRIVER_PATH”: “disable”
}
env_dict = dict(env_os, **sen_env)

I am attempting to also run the L2A_Process in python (Spyder).
I do not have path problems with Sen2cor (yet at least…) in stead using the following code i just get
Out[165]: 0

L2A_Process= ‘/Users/freddiehunter/Work/Sen2Cor_Setup/Sen2Cor-02.05.05-Darwin64/L2A_Bashrc’
scene=’/Users/freddiehunter/Work/GIS Course

have also tried this path L2A_Process= ‘/Users/freddiehunter/Work/Sen2Cor_Setup/Sen2Cor-02.05.05-Darwin64/bin/L2A_Process’

scene=’/Users/freddiehunter/Work/GIS\ Course\ Work/Dissertation/Image_Processing/Spyder_scripts/Downloading_Sen2/S2A_MSIL1C_20180514T073611_N0206_R092_T36MZC_20180514T095515.SAFE’

subprocess.check_call([L2A_Process , str(scene)],shell=True)
Out[165]: 0

Any Ideas?

Thanks!

Hi. I had the same problem. In am running on ubuntu18.04. I can make it working like this:

import subprocess
import os


cmd = ' L2A_Process "full_path_to_my_tile/" '


if '__main__' == __name__:
    my_env = os.environ.copy()
    my_env['PATH'] = '/home/ubuntu/Sen2Cor-02.08.00-Linux64/bin:' + my_env['PATH']
    my_env['SEN2COR_HOME'] = '/home/ubuntu/sen2cor/2.8'
    my_env['SEN2COR_BIN'] = '/home/ubuntu/Sen2Cor-02.08.00-Linux64/lib/python2.7/site-packages/sen2cor'
    my_env['LC_NUMERIC'] = 'C'
    my_env['GDAL_DATA'] = '/home/ubuntu/Sen2Cor-02.08.00-Linux64/share/gdal'
    my_env['GDAL_DRIVER_PATH']= 'disable'

    try:
        result = subprocess.check_output(cmd, env=my_env, shell=True)
        print(result)
    except subprocess.CalledProcessError as e:
        print(e)

1 Like