{"id":352,"date":"2013-02-03T10:43:14","date_gmt":"2013-02-03T10:43:14","guid":{"rendered":"http:\/\/www.jontrinder.com\/blog\/?p=352"},"modified":"2013-02-03T10:51:03","modified_gmt":"2013-02-03T10:51:03","slug":"matplotlib-basemap-pyinstaller","status":"publish","type":"post","link":"https:\/\/www.jontrinder.com\/blog\/?p=352","title":{"rendered":"Matplotlib, BaseMap, Pyinstaller"},"content":{"rendered":"<p>(brief random notes, that may help someone else)<br \/>\nA brief tale of getting a matplotlib and basemap to work with pyinstaller. There are two strands to this the Linux and Windows.<\/p>\n<p>This is mostly the linux story.<\/p>\n<p>Step by step, to how I got working.<\/p>\n<p>I was trying to build  a single directory solution and a single file solution.<br \/>\nFinal conclusion was best to make the application single file and dont include the BaseMap data. then supply the basemap data separately.<\/p>\n<p>This makes it easier to share the basemap data with other applications.<\/p>\n<p>Dependent upon whether you are working on a machine that has matplotlib\/basemap installed or not did change how things behaved.<\/p>\n<p>In what follows dev_machine is my dev machine with all packages installed, the target machine is the users machine and has none of the dev tools installed.<br \/>\n<strong>Things needed&#8230;<\/strong><br \/>\nOn target machine it needed a matplotlibrc,<br \/>\nAs a fiddle (thanks to this post <a href=\"http:\/\/ubuntuforums.org\/archive\/index.php\/t-1506538.html\">http:\/\/ubuntuforums.org\/archive\/index.php\/t-1506538.html<\/a>) I copied my dev machine \/etc\/matplotlibrc to the directory in which the exectuable was stored on the target machine<\/p>\n<p>the next problem  was<\/p>\n<p>IOError: proj data directory not found. Expecting it at: \/usr\/share\/basemap\/data<\/p>\n<p>This required a tweak to\u00a0\/usr\/share\/pyshared\/mpl_toolkits\/basemap\/pyproj<br \/>\nin new install ended up in \/usr\/local\/lib\/python2.7\/dist-packages\/mpl_toolkits\/basemap<\/p>\n<p>as per this post\u00a0<a href=\"http:\/\/code.google.com\/p\/pyproj\/issues\/detail?id=40&amp;q=PROJ_DIR\">http:\/\/code.google.com\/p\/pyproj\/issues\/detail?id=40&amp;q=PROJ_DIR<\/a><\/p>\n<p>Which boils down to around line 239, replace this line<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n\r\npyproj_datadir = '\/usr\/share\/basemap\/data'\r\n\r\n<\/pre>\n<p>with<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nif 'PROJ_DIR' in os.environ:\r\n   pyproj_datadir = os.environ&#x5B;'PROJ_DIR']\r\nelse:\r\n    pyproj_datadir = os.sep.join(&#x5B;os.path.dirname(__file__), 'data'])\r\n<\/pre>\n<p>The setting an enviroment variable to wherever you have the basemap data<br \/>\nin my setup this was in a folder where the executable was<br \/>\n export BASEMAPDATA=.\/basemap\/data<\/p>\n<p>Next rebuild the pyinstaller files and try again&#8230;.<br \/>\nexport PROJ_DIR=.\/basemap\/data<\/p>\n<p>just didnt work!<br \/>\ncopied \/etc\/matplotlibrc from dev machine into the same folder as the executable and<br \/>\nit worked!&#8230;.As long as I supplied the basemap data in a folder called basemap\/data<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(brief random notes, that may help someone else) A brief tale of getting a matplotlib and basemap to work with pyinstaller. There are two strands to this the Linux and Windows. This is mostly the linux story. Step by step, &hellip; <a href=\"https:\/\/www.jontrinder.com\/blog\/?p=352\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[80,48,85,1],"tags":[],"class_list":["post-352","post","type-post","status-publish","format-standard","hentry","category-computing","category-matplotlib","category-python","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=352"}],"version-history":[{"count":9,"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/352\/revisions"}],"predecessor-version":[{"id":362,"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/352\/revisions\/362"}],"wp:attachment":[{"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}