[GRASS-dev] Add support for Python3

Pietro peter.zamb at gmail.com
Mon Jul 27 12:58:09 PDT 2015

Hi Markus,

On Mon, Jul 27, 2015 at 4:24 PM, Markus Neteler <neteler at osgeo.org> wrote:
> On Mon, Jul 27, 2015 at 1:59 PM, Pietro <peter.zamb at gmail.com> wrote:
> ...
>> ok, I've commited the changes in lib/init/grass.py and in the
>> lib/python/gunittest/*
> Please post to the list how to switch to Python3 in case that multiple
> versions are available.
> Like this more testers may join.

You are righ, here some instruction to test and find bugs...

You must have python3 installed on your machine, from a terminal

python3 /usr/bin/grass71 -getxt ~/docdat/gis/nc_spm_08_grass7/py34 -c

then start a python interpreter and execute some code
[Note1: this example should not work on your machine since I didn't
commit this part so far;
 Note2: GRASS with python3 it is working only in text mode no GUI!]:

$ python3
>>> from grass.script import core as gcore
>>> gcore.gisenv()
{'GISDBASE': '/home/pietro/docdat/gis', 'GUI': 'gtext', 'MAPSET':
'py34', 'LOCATION_NAME': 'nc_spm_08_grass7'}

To check if the result in python2 is the same then open a new terminal
and execute

$ python2 /usr/bin/grass71 -getxt ~/docdat/gis/nc_spm_08_grass7/py27 -c

$ python2
>>> from grass.script import core as gcore
>>> gcore.gisenv()
{u'LOCATION_NAME': unc_spm_08_grass7', u'GISDBASE':
u'/home/pietro/docdat/gis', u'MAPSET': u'py27', u'GUI': u'gtext'}

You can also start executing Vaclav's unittest library, go to a directory:

$ cd lib/python/script
$ python3 -m grass.gunittest.main --location nc_spm_08_grass7 --location-type nc
test_start_command_functions_nc from . failed
test_start_command_functions from . failed
test_doctests from . failed

Executed 3 test files in 0:00:09.962775.
>From them 0 files (0%) were successful and 3 files (100%) failed.

$ python2 -m grass.gunittest.main --location nc_spm_08_grass7 --location-type nc

Executed 3 test files in 0:00:10.358305.
>From them 3 files (100%) were successful and 0 files (0%) failed.

or execute a specific test file with:

$ python3 testsuite/test_start_command_functions_nc.py

So far the test in the script directory are still failing I'm working
to fix them... :-)

All the best


More information about the grass-dev mailing list