-
Notifications
You must be signed in to change notification settings - Fork 287
Description
The following is for anyone who uses TileStache in combination with Mapnik and Python 3.8 (e.g. in Ubuntu 20.4) and encounters the following error:
ImportError: cannot import name 'parse_qs' from 'cgi' (/usr/lib/python3.8/cgi.py)
The reason this error occurs is as follows:
parse_qs, parse_qsl, and escape are removed from the cgi module. They are deprecated in Python 3.2 or older. They should be imported from the urllib.parse and html modules instead. Source
The following steps should be performed to fix this:
-
Open a Terminal (Ctrl + alt + t on your keyboard)
-
Open the TileStache Python 3 compatibility file by running the following command
sudo nano /home/geostack/.local/lib/python3.8/site-packages/TileStache/py3_compat.py
-
Change the following:
try:
import urllib.request as urllib2
import http.client as httplib
from urllib.parse import urlparse, urljoin, parse_qsl
from urllib.request import urlopen
from cgi import parse_qs
from _thread import allocate_lock
unichr = chr
except ImportError:
# Python 2
import httplib
import urllib2
from urlparse import urlparse, urljoin, parse_qs, parse_qsl
from urllib import urlopen
from thread import allocate_lock
unichr = unichr
TO:
import urllib.request as urllib2
import http.client as httplib
from urllib.parse import urlparse, urljoin, parse_qsl, parse_qs
from urllib.request import urlopen
# from cgi import parse_qs
from _thread import allocate_lock
unichr = chr
-
Save the file (Ctrl + s on your keyboard)
-
Run Tilestache