Using cartopy in offline distributable - python

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!

Related

Python Barcode OSError: cannot open resources error while running .exe file

I'm trying to make an application with a module python barcode when I compiled it raw it worked well but when I tried to turn it into an exe (using pyinstaller) this gives me the error
File "barcode\base.py", line 67, in save
File "barcode\ean.py", line 95, in render
File "barcode\base.py", line 102, in render
File "barcode\writer.py", line 188, in render
File "barcode\writer.py", line 280, in _paint_text
File "PIL\ImageFont.py", line 959, in truetype
File "PIL\ImageFont.py", line 956, in freetype
File "PIL\ImageFont.py", line 247, in __init__
OSError: cannot open resource
Code that I'm currently running
bar_code = 310400070000555
bar_code = str(bar_code)
bar_code_obj = EAN13(bar_code, writer=ImageWriter())
bar_code_obj.save("bar_code_img")

to_gbq error in vscode but able to run in google colab

I had tried a testing version in google colab for uploading the dataframe to gbq but in vs code I had result this error message
File "/usr/local/lib/python3.9/site-packages/pandas_gbq/gbq.py", line 1193, in to_gbq connector.load_data( File "/usr/local/lib/python3.9/site-packages/pandas_gbq/gbq.py", line 586, in load_data chunks = load.load_chunks( File "/usr/local/lib/python3.9/site-packages/pandas_gbq/load.py", line 237, in load_chunks load_parquet( File "/usr/local/lib/python3.9/site-packages/pandas_gbq/load.py", line 129, in load_parquet client.load_table_from_dataframe( File "/usr/local/lib/python3.9/site-packages/google/cloud/bigquery/client.py", line 2671, in load_table_from_dataframe _pandas_helpers.dataframe_to_parquet( File "/usr/local/lib/python3.9/site-packages/google/cloud/bigquery/_pandas_helpers.py", line 586, in dataframe_to_parquet arrow_table = dataframe_to_arrow(dataframe, bq_schema) File "/usr/local/lib/python3.9/site-packages/google/cloud/bigquery/_pandas_helpers.py", line 529, in dataframe_to_arrow bq_to_arrow_array(get_column_or_index(dataframe, bq_field.name), bq_field) File "/usr/local/lib/python3.9/site-packages/google/cloud/bigquery/_pandas_helpers.py", line 290, in bq_to_arrow_array return pyarrow.Array.from_pandas(series, type=arrow_type) File "pyarrow/array.pxi", line 915, in pyarrow.lib.Array.from_pandas File "pyarrow/array.pxi", line 312, in pyarrow.lib.array File "pyarrow/array.pxi", line 83, in pyarrow.lib._ndarray_to_array File "pyarrow/error.pxi", line 122, in pyarrow.lib.check_status pyarrow.lib.ArrowTypeError: Expected bytes, got a 'list' object
Hope to know how to solve this issue and why will to able to run in colab but error in vscode?
I hope to know how to solve this issue and why will it happen. Thank you very much

Tensorflow object detection model faster_rcnn_inception_resnet_v2_atrous_oid.config is showing following problrm?

I am using faster_rcnn_inception_resnet_v2_atrous_oid.config. I shows the following problem. Help me please:
File "train.py", line 167, in <module>
tf.app.run()
File "C:\Users\mgp21\Anaconda3\envs\deeplearning\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
_sys.exit(main(argv))
File "train.py", line 92, in main
FLAGS.pipeline_config_path)
File "C:\Users\mgp21\Anaconda3\envs\deeplearning\models\research\object_detection\utils\config_util.py", line 88, in get_configs_from_pipeline_file
text_format.Merge(proto_str, pipeline_config)
File "C:\Users\mgp21\Anaconda3\envs\deeplearning\lib\site-packages\google\protobuf\text_format.py", line 533, in Merge
descriptor_pool=descriptor_pool)
File "C:\Users\mgp21\Anaconda3\envs\deeplearning\lib\site-packages\google\protobuf\text_format.py", line 587, in MergeLines
return parser.MergeLines(lines, message)
File "C:\Users\mgp21\Anaconda3\envs\deeplearning\lib\site-packages\google\protobuf\text_format.py", line 620, in MergeLines
self._ParseOrMerge(lines, message)
File "C:\Users\mgp21\Anaconda3\envs\deeplearning\lib\site-packages\google\protobuf\text_format.py", line 635, in _ParseOrMerge
self._MergeField(tokenizer, message)
File "C:\Users\mgp21\Anaconda3\envs\deeplearning\lib\site-packages\google\protobuf\text_format.py", line 735, in _MergeField
merger(tokenizer, message, field)
File "C:\Users\mgp21\Anaconda3\envs\deeplearning\lib\site-packages\google\protobuf\text_format.py", line 823, in _MergeMessageField
self._MergeField(tokenizer, sub_message)
File "C:\Users\mgp21\Anaconda3\envs\deeplearning\lib\site-packages\google\protobuf\text_format.py", line 703, in _MergeField
(message_descriptor.full_name, name))
google.protobuf.text_format.ParseError: 160:3 : Message type "object_detection.protos.TrainConfig" has no field named "fine_tune_checkpoint_type".
It's a matter of TensorFlow version, you're probably using a newer .config with an older TensorFlow, see https://github.com/tensorflow/models/issues/4056.

Erasing Python download

I am trying to use the TensorFlow image classifier but halfway through the download my internet connection got lost and I could not download the file.
I understand that I have to delete the partial download and run again to make this work but I am not sure where the file is or how to find it.
I tried searching for the file name "Inception-2015-12-05.tgz" and nothing showed up. My guess is that there is a temporary file name when I downloaded it.
File "classify_image.py", line 227, in <module>
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 126, in run
_sys.exit(main(argv))
File "classify_image.py", line 190, in main
maybe_download_and_extract()
File "classify_image.py", line 186, in maybe_download_and_extract
tarfile.open(filepath, 'r:gz').extractall(dest_directory)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tarfile.py", line 2007, in extractall
numeric_owner=numeric_owner)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tarfile.py", line 2049, in extract
numeric_owner=numeric_owner)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tarfile.py", line 2119, in _extract_member
self.makefile(tarinfo, targetpath)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tarfile.py", line 2168, in makefile
copyfileobj(source, target, tarinfo.size, ReadError, bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tarfile.py", line 248, in copyfileobj
buf = src.read(bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gzip.py", line 276, in read
return self._buffer.read(size)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_compression.py", line 68, in readinto
data = self.read(len(byte_view))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gzip.py", line 482, in read
raise EOFError("Compressed file ended before the "
EOFError: Compressed file ended before the end-of-stream marker was reached
Delete the /tmp/imagenet folder, then restart the download.

running matplotlib with no DISPLAY

When matlplotlib run (from summarize_taxa_through_plots.py) I got the error:
...
raise RuntimeError('Invalid DISPLAY variable')
RuntimeError: Invalid DISPLAY variable
I saw this problem in a lot of sites, the solution is to change user's matplotlirc or global one:
backend:qt4agg
to
backend:agg
I change the global matplotlibrc.
Now when I run the program use matplotlib I get:
Command returned exit status: 1
Stdout:
Stderr
Traceback (most recent call last):
File "/path/to/python/2.7.6/bin/plot_taxa_summary.py", line 278, in <module>
main()
File "/path/to/python/2.7.6/bin/plot_taxa_summary.py", line 274, in main
resize_nth_label, label_type, include_html_legend)
File "/path/to/python/2.7.6/lib/python2.7/site-packages/qiime/plot_taxa_summary.py", line 1138, in make_all_charts
resize_nth_label, label_type, include_html_legend))
File "/path/to/python/2.7.6/lib/python2.7/site-packages/qiime/plot_taxa_summary.py", line 1073, in get_counts
label_type, include_html_legend))
File "/path/to/python/2.7.6/lib/python2.7/site-packages/qiime/plot_taxa_summary.py", line 861, in make_HTML_table
props={'title': title})
File "/path/to/python/2.7.6/lib/python2.7/site-packages/qiime/plot_taxa_summary.py", line 662, in make_area_bar_chart
background_color, img_abs, generate_image_type, dpi)
File "/path/to/python/2.7.6/lib/python2.7/site-packages/qiime/plot_taxa_summary.py", line 187, in make_legend
shadow=False, fancybox=False)
File "/path/to/python/2.7.6/lib/python2.7/site-packages/matplotlib/figure.py", line 1251, in legend
l = Legend(self, handles, labels, *args, **kwargs)
File "/path/to/python/2.7.6/lib/python2.7/site-packages/matplotlib/legend.py", line 385, in __init__
self._init_legend_box(handles, labels, markerfirst)
File "/path/to/python/2.7.6/lib/python2.7/site-packages/matplotlib/legend.py", line 654, in _init_legend_box
fontsize, handlebox))
File "/path/to/python/2.7.6/lib/python2.7/site-packages/matplotlib/legend_handler.py", line 119, in legend_artist
fontsize, handlebox.get_transform())
File "/path/to/python/2.7.6/lib/python2.7/site-packages/matplotlib/legend_handler.py", line 252, in create_artists
self.update_prop(p, orig_handle, legend)
File "/path/to/python/2.7.6/lib/python2.7/site-packages/matplotlib/legend_handler.py", line 78, in update_prop
legend._set_artist_props(legend_handle)
File "/path/to/python/2.7.6/lib/python2.7/site-packages/matplotlib/legend.py", line 401, in _set_artist_props
a.set_figure(self.figure)
File "/path/to/python/2.7.6/lib/python2.7/site-packages/matplotlib/artist.py", line 640, in set_figure
raise RuntimeError("Can not put single artist in "
RuntimeError: Can not put single artist in more than one figure
Any idea?
The suggestion is to downgrade the matplotlib version you have and to use something like 1.4.x. See this issue in the qiime GitHub repo.

Categories

Resources