I am trying to use GRASS 7 from Python without explicitly creating a location. I am starting with the script provided at the GRASS-Wiki. This script tries to create a new location in the /tmp/ folder with the following lines:

p = subprocess.Popen(startcmd, shell=True, 
                     stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if p.returncode != 0:
    print >>sys.stderr, 'ERROR: %s' % err
    print >>sys.stderr, 'ERROR: Cannot generate location (%s)' % startcmd
    print 'Created location %s' % location_path

But this code bit is failing with these cryptic messages:

grass70 -c epsg:3044 -e /tmp/grassdata/35ba41efc124ae1c791f5c538713d948
Created location /tmp/grassdata/35ba41efc124ae1c791f5c538713d948
grass70 -c epsg:3044 -e /tmp/grassdata/8e9e4baf21ef6831d4f7b1c4096259e7
ERROR: Fix system locale settings and then try again.

ERROR: Cannot generate location (grass70 -c epsg:3044 -e /tmp/grassdata/8e9e4baf21ef6831d4f7b1c4096259e7)

How can this script be fixed?

1 Answer 1


GRASS expects the LC_ALL environment variable to be set, otherwise it issues this error. As it happens, distributions such as Ubuntu have this environment variable unset by default.

So the fix is to set up this variable manually at the beginning of the script, something like:

if sys.platform.startswith('linux'):
    os.environ['LC_ALL'] = "en_GB.UTF-8"

This goes in line 55 of the script referenced in the question above.

  • Should this be changed in GRASS GIS itself?
    – markusN
    Jun 26, 2016 at 1:00
  • This solved error in ubuntu
    – nish
    Oct 15, 2020 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.