Using cartopy in offline distributable

Viewed 166

I have made a simple application/GUI using PyQt5 that draws a map using Cartopy and allows users to drop points on the map. Everything works fine when I have access to Wifi. I used pyinstaller to bundle it up as one application so I can send it to my friends.

However, if you do not have access to the internet, cartopy is unable to draw the map because it cannot access the shapefiles which it downloads into the ~.local/share/cartopy/shapefiles location. I tried including the shapefiles using the --add-data command in pyinstaller but it didn't work?

I used sys._MEIPASS to include a CSV of other data, and it works just fine to read that data (coordinates of some landmarks).

The error looks something like:

  File "site-packages\matplotlib\backends\backend_agg.py", line 393, in draw
  File "site-packages\matplotlib\artist.py", line 38, in draw_wrapper
  File "site-packages\matplotlib\figure.py", line 1735, in draw
  File "site-packages\matplotlib\image.py", line 137, in _draw_list_compositing_images
  File "site-packages\matplotlib\artist.py", line 38, in draw_wrapper
  File "site-packages\cartopy\mpl\geoaxes.py", line 479, in draw
  File "site-packages\matplotlib\artist.py", line 38, in draw_wrapper
  File "site-packages\matplotlib\axes\_base.py", line 2630, in draw
  File "site-packages\matplotlib\image.py", line 137, in _draw_list_compositing_images
  File "site-packages\matplotlib\artist.py", line 38, in draw_wrapper
  File "site-packages\cartopy\mpl\feature_artist.py", line 155, in draw
  File "site-packages\cartopy\feature\__init__.py", line 302, in intersecting_geometries
  File "site-packages\cartopy\feature\__init__.py", line 110, in intersecting_geometries
  File "site-packages\cartopy\feature\__init__.py", line 284, in geometries
  File "site-packages\cartopy\io\shapereader.py", line 295, in natural_earth
  File "site-packages\cartopy\io\__init__.py", line 222, in path
  File "site-packages\cartopy\io\shapereader.py", line 350, in acquire_resource
  File "site-packages\cartopy\io\__init__.py", line 261, in _urlopen
  File "urllib\request.py", line 222, in urlopen
  File "urllib\request.py", line 525, in open
  File "urllib\request.py", line 542, in _open
  File "urllib\request.py", line 502, in _call_chain
  File "urllib\request.py", line 1393, in https_open
  File "urllib\request.py", line 1353, in do_open
  urllib.error.URLError: <urlopen error [Errno 11001] getaddrinfo failed>

In the code itself, I have:

os.chdir(sys._MEIPASS)
datapath1 = 'data\\ne_50m_coastline.shp'

And further below

coastline = datapath1
map.add_feature(coastline, zorder=3)

But, as shown in the error above, when I run the executable with no internet access, it does not find the shapefile included in the exe onefile.

Thanks in advance for any help!

0 Answers
Related