mapbox / mapboxgl-jupyter

Use Mapbox GL JS to visualize data in a Python Jupyter notebook
MIT License
661 stars 136 forks source link

TemplateNotFound in conda environment #163

Open Sieboldianus opened 5 years ago

Sieboldianus commented 5 years ago

I am trying to run the example Jupyter Notebook in ../master/examples/notebooks/scale-annotation.ipynb

I've set up my environment with conda: conda install -c conda-forge mapboxgl

The file paths I've tested:

  1. relative path
--mapboxgl-jupyter
----scale-annotation.ipynb
----data
------healthcare_points.geojson
----templates
------circle.html
  1. up directory path
--mapboxgl-jupyter
----scale-annotation.ipynb
--data
----healthcare_points.geojson
--templates
----circle.html
  1. local
--mapboxgl-jupyter
----scale-annotation.ipynb
----healthcare_points.geojson
----circle.html

All of these give me:

~/miniconda3/envs/jupyter_env/lib/python3.6/site-packages/jinja2/loaders.py in load(self, environment, name, globals)
    111         # first we try to get the source for this template together
    112         # with the filename and the uptodate function.
--> 113         source, filename, uptodate = self.get_source(environment, name)
    114 
    115         # try to load the code from the bytecode cache if there is a

~/miniconda3/envs/jupyter_env/lib/python3.6/site-packages/jinja2/loaders.py in get_source(self, environment, template)
    233         p = '/'.join((self.package_path,) + tuple(pieces))
    234         if not self.provider.has_resource(p):
--> 235             raise TemplateNotFound(template)
    236 
    237         filename = uptodate = None

TemplateNotFound: circle.html
akacarlyann commented 5 years ago

@Sieboldianus just out of curiosity: are you able to execute any of the notebooks in your conda installation?

Sieboldianus commented 5 years ago

Yes, I've just tested with cloning the entire Github Repo and walking through the example notebooks folder. I get errors for all of these, e.g.:

linestring-viz.ipynb

~/miniconda3/envs/jupyter_env/lib/python3.7/site-packages/jinja2/loaders.py in load(self, environment, name, globals)
    111         # first we try to get the source for this template together
    112         # with the filename and the uptodate function.
--> 113         source, filename, uptodate = self.get_source(environment, name)
    114 
    115         # try to load the code from the bytecode cache if there is a

~/miniconda3/envs/jupyter_env/lib/python3.7/site-packages/jinja2/loaders.py in get_source(self, environment, template)
    233         p = '/'.join((self.package_path,) + tuple(pieces))
    234         if not self.provider.has_resource(p):
--> 235             raise TemplateNotFound(template)
    236 
    237         filename = uptodate = None

TemplateNotFound: linestring.html

image-vis-type-example.ipynb

~/miniconda3/envs/jupyter_env/lib/python3.7/site-packages/jinja2/loaders.py in load(self, environment, name, globals)
    111         # first we try to get the source for this template together
    112         # with the filename and the uptodate function.
--> 113         source, filename, uptodate = self.get_source(environment, name)
    114 
    115         # try to load the code from the bytecode cache if there is a

~/miniconda3/envs/jupyter_env/lib/python3.7/site-packages/jinja2/loaders.py in get_source(self, environment, template)
    233         p = '/'.join((self.package_path,) + tuple(pieces))
    234         if not self.provider.has_resource(p):
--> 235             raise TemplateNotFound(template)
    236 
    237         filename = uptodate = None

TemplateNotFound: image.html

Do I have to do anything to set the template resource folder?

akacarlyann commented 5 years ago

Ah I see. I'm not sure if the conda distribution task was finished in #65, since that issue is still open. @ryanbaumann do you have more info?

pybanaszak commented 5 years ago

I have the same issue on my side using Anaconda 2019.07. I already used your package without any issue.

To solve this issue I had to add the templates folder of your repo in this repo on my mac : ~/anaconda3/lib/python3.7/site-packages/mapboxgl/ now the map is showing inside the iframe, but no data/markers are showing up.

My code :

from mapboxgl.utils import *
from mapboxgl.viz import *

# Generate color stops from colorBrewer
measure_color = 'Appearances'
color_breaks = [round(appearances_per_city[measure_color].quantile(q=x*0.1), 2) for x in range(2, 10)]
color_stops = create_color_stops(color_breaks, colors='Blues')

# Generate radius breaks from data domain and circle-radius range
measure_radius = 'Appearances'
radius_breaks = [round(appearances_per_city[measure_radius].quantile(q=x*0.1) , 2) for x in range(2,10)]
radius_stops = create_radius_stops(radius_breaks, 0.5, 9)

# Create the viz
viz = GraduatedCircleViz('appearances.geojson',
                         access_token=token,
                         height='320px',
                         color_property='Appearances',
                         color_stops=color_stops,
                         radius_property='Appearances',
                         stroke_color='black',
                         stroke_width=0.5,
                         radius_stops=radius_stops,
                         center = (20, 50),
                         zoom=3,
                         below_layer='waterway-label')

viz.show()

Here is the error message I get without the template folder :

---------------------------------------------------------------------------
TemplateNotFound                          Traceback (most recent call last)
<ipython-input-50-f44a65577407> in <module>
     27 
     28 
---> 29 viz.show()

~/anaconda3/lib/python3.7/site-packages/mapboxgl/viz.py in show(self, **kwargs)
    255     def show(self, **kwargs):
    256         # Load the HTML iframe
--> 257         html = self.create_html(**kwargs)
    258         map_html = self.as_iframe(html)
    259 

~/anaconda3/lib/python3.7/site-packages/mapboxgl/viz.py in create_html(self, filename)
    355             return None
    356         else:
--> 357             return templates.format(self.template, **options)
    358 
    359 

~/anaconda3/lib/python3.7/site-packages/mapboxgl/templates.py in format(viz, **kwargs)
      9 
     10 def format(viz, **kwargs):
---> 11     template = env.get_template('{}.html'.format(viz))
     12     return template.render(viz=viz, **kwargs)

~/anaconda3/lib/python3.7/site-packages/jinja2/environment.py in get_template(self, name, parent, globals)
    828         if parent is not None:
    829             name = self.join_path(name, parent)
--> 830         return self._load_template(name, self.make_globals(globals))
    831 
    832     @internalcode

~/anaconda3/lib/python3.7/site-packages/jinja2/environment.py in _load_template(self, name, globals)
    802                                          template.is_up_to_date):
    803                 return template
--> 804         template = self.loader.load(self, name, globals)
    805         if self.cache is not None:
    806             self.cache[cache_key] = template

~/anaconda3/lib/python3.7/site-packages/jinja2/loaders.py in load(self, environment, name, globals)
    111         # first we try to get the source for this template together
    112         # with the filename and the uptodate function.
--> 113         source, filename, uptodate = self.get_source(environment, name)
    114 
    115         # try to load the code from the bytecode cache if there is a

~/anaconda3/lib/python3.7/site-packages/jinja2/loaders.py in get_source(self, environment, template)
    233         p = '/'.join((self.package_path,) + tuple(pieces))
    234         if not self.provider.has_resource(p):
--> 235             raise TemplateNotFound(template)
    236 
    237         filename = uptodate = None

TemplateNotFound: graduated_circle.html
ryanbaumann commented 5 years ago

@akacarlyann correct, I did not publish the Anaconda distribution currently in Conda Forge. That's why the issue in this repo (https://github.com/mapbox/mapboxgl-jupyter/issues/65) is still open.

raerickson commented 4 years ago

@ryanbaumann as an FYI, this issue is still haunting Conda Forge over a year later. For anybody looking for the quick fix in the terminal, here it is:

pip uninstall mapboxgl
pip install mapboxgl
kinow commented 2 years ago

There are two archives in PYPI, one the source distribution, and the other a wheel file. The wheel contains the templates folder, but the source distribution doesn't.

The conda package is built using the PYPI source distribution, so the Conda Forge installation results in a module without the templates folder.

I downloaded the wheel file, unzipped it, then copied the templates folder over to my conda env directory ~/Development/python/miniconda3/envs/csl-load-count-ml/lib/python3.8/site-packages/mapboxgl. Now my notebook is running OK.