2

I am a self-taught QGIS user with low computer skills.

I run QGIS 2.10 on Ubuntu 15.10. I am trying to use Alexander Hajmal's tile_writer script (http://alephnull.net/software/gis/tile_writer.shtml). However, when I attempt to execute the script I get this message:

Traceback (most recent call last): File "", line 1, in File "/home/brian/tile_writer.0.2.1/tile_writer.py", line 64, in from globalmercator import GlobalMercator File "/usr/lib/python2.7/dist-packages/qgis/utils.py", line 478, in _import mod = _builtin_import(name, globals, locals, fromlist, level) ImportError: No module named globalmercator

I have globalmercator.py on my home directory along with tilewriter.py, in a folder named "tile_writer.0.2.1". When the script didn't work I tried to add the following two lines to my etc/environment file:

PYTHONPATH="${PYTHONPATH}:/home/brian/tile_writer.0.2.1/globalmercator.py"
export PYTHONPATH

Unfortunately the results were still the same.

How do I properly set the path, or whatever else I am supposed to do?

0

1 Answer 1

3

You don't need to fix the PYTHONPATH here, it is a pure Python PATH problem

import os 
working_directory = os.getcwd()

gives you the working directory. All Python files should be in this folder

>>> import os
>>> os.getcwd()
'/Users/Shared/tile_writer.0.2.1'
>>> import globalmercator
>>> 

If you are not working in this folder, use sys.path.append

>>> import os
>>> os.getcwd()
'/Users/Shared'
>>> import sys
>>> import globalmercator
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named globalmercator
>>> sys.path.append("/Users/Shared/tile_writer.0.2.1")
>>> import globalmercator
>>> 

If you really want to use a valid PYTHONPATH (same as sys.path.append)

$ export PYTHONPATH=/Users/Shared/tile_writer.0.2.1
$ python
 Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
 ....
>>> import globalmercator
>>> 

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