Testing and fixing his code.
Here the whole run,using virtual environment.
C:\Python36
λ python -m venv geo_test
C:\Python36
λ cd geo_test
C:\Python36\geo_test
λ ls
Include/ Lib/ Scripts/ pyvenv.cfg
C:\Python36\geo_test
λ c:\python36\geo_test\Scripts\activate.bat
(geo_test) C:\Python36\geo_test
λ pip -V
pip 9.0.1 from c:\python36\geo_test\lib\site-packages (python 3.6)
(geo_test) C:\Python36\geo_test
λ pip install geotext-0.3.0-py2.py3-none-any.whl
Processing c:\python36\geo_test\geotext-0.3.0-py2.py3-none-any.whl
Installing collected packages: geotext
Successfully installed geotext-0.3.0
(geo_test) C:\Python36\geo_test
λ python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from geotext import GeoText
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python36\geo_test\lib\site-packages\geotext\__init__.py", line 7, in <module>
from .geotext import GeoText
File "C:\Python36\geo_test\lib\site-packages\geotext\geotext.py", line 87, in <module>
class GeoText(object):
File "C:\Python36\geo_test\lib\site-packages\geotext\geotext.py", line 103, in GeoText
index = build_index()
File "C:\Python36\geo_test\lib\site-packages\geotext\geotext.py", line 77, in build_index
cities = read_table(get_data_path('cities15000.txt'), usecols=[1, 8])
File "C:\Python36\geo_test\lib\site-packages\geotext\geotext.py", line 54, in read_table
for line in lines:
File "C:\Python36\geo_test\lib\site-packages\geotext\geotext.py", line 51, in <genexpr>
lines = (line for line in f if not line.startswith(comment))
File "C:\Python36\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 165: character maps to <undefined>
Fix:
Line 45
geotext.py
:
with open(filename, 'r') as f:
To:
with open(filename, 'r', encoding='utf-8') as f:
Test.
(geo_test) C:\Python36\geo_test
λ python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from geotext import GeoText
>>> places = GeoText("London is a great city")
>>> places.cities
['London']
>>> GeoText('New York, Texas, and also China').country_mentions
OrderedDict([('US', 2), ('CN', 1)])
>>> places = GeoText("Oslo is a great city")
>>> places.cities
['Oslo']
Edit:
There where 1-bug rapport about this.
So i have given this info to author of geotext on GitHub.