[GIS] UnicodeDecodeError: While installing gdal in a new Python Virtual Environment

gdalpython

I was trying to create a Python Virtual Environment for some initial GIS development. I installed pip and virtualenv and then tried the following commands from the Linux-Terminal to accomplish the task

$ cd Test/virtualenvs_for_test
$ virtualenv --no-site-packages postgis-cb-env
$ source postgis-cb-env/bin/activate
$ pip install gdal

But found the following error message:

error: command 'gcc' failed with exit status 1

Cleaning up…
Command /home/gislinux/Test/virtualenvs/postgis-cb-env/bin/python -c "import setuptools, tokenize;file='/home/gislinux/Test/virtualenvs/postgis-cb-env/build/gdal/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install –record /tmp/pip-h8eZSu-record/install-record.txt –single-version-externally-managed –compile –install-headers /home/gislinux/Test/virtualenvs/postgis-cb-env/include/site/python2.7 failed with error code 1 in /home/gislinux/Test/virtualenvs/postgis-cb-env/build/gdal
Traceback (most recent call last):
File "/home/gislinux/Test/virtualenvs/postgis-cb-env/bin/pip", line 11, in
sys.exit(main())
File "/home/gislinux/Test/virtualenvs/postgis-cb-env/local/lib/python2.7/site-packages/pip/init.py", line 185, in main
return command.main(cmd_args)
File "/home/gislinux/Test/virtualenvs/postgis-cb-env/local/lib/python2.7/site-packages/pip/basecommand.py", line 161, in main
text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 42: ordinal not in range(128)

I have no sure idea what this error is exactly. Although initial web-hunting suggested a need to change encoding from ascii to utf8, but how?

Best Answer

You must install libgdal-dev and then install gdal with paths:

export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
Related Question