Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jupyter-gmaps loaded but cannot be instantiated #359

Open
ylnhari opened this issue Sep 6, 2022 · 7 comments
Open

jupyter-gmaps loaded but cannot be instantiated #359

ylnhari opened this issue Sep 6, 2022 · 7 comments

Comments

@ylnhari
Copy link

ylnhari commented Sep 6, 2022

Issue:

I was able to successfully create gmaps figure object but when tried to display the map in a jupyter cell, receiving the following error ->

[Open Browser Console for more detailed log - Double click to close this message]
Model class 'FigureModel' from module 'jupyter-gmaps' is loaded but can not be instantiated
TypeError: Class constructor L cannot be invoked without 'new'
at new t (http://localhost:8888/nbextensions/jupyter-gmaps/index.js?v=20220906161950:39:179771)
at u._make_model (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20220906161950:2:747368)

It was working fine until few weeks ago. I tried re-installing jupyter-gmaps and enabling the gmaps jupyter extension, created fresh virtual environment, tried reinstalling node.js, reinstalling jupyter etc. but got no luck. I suspect some package version issues could be a reason for this as this setup is working fine until few weeks ago please help.

Note:- also ipywidgets should not be the issue because i was able to create widgets using it and they are working fine in the same jupyter notebook.

Input code used to generate a figure :

import gmaps
gmaps.configure(api_key=google_maps_key)
fig = gmaps.figure()
markers = gmaps.marker_layer(marker_locations) # marker_locations = [(latitude1, longitude1), (latitude2, longitude2),......,]
fig.add_layer(markers)

Requirements file:

python=3.7.0
tqdm
pandas
openpyxl
xlrd
requests
ortools
jupyter
gmaps

Screen shot of the error:
image

@arooj1
Copy link

arooj1 commented Oct 7, 2022

i am facing the same issue. Any solution so far?

@sbenston
Copy link

sbenston commented Oct 9, 2022

I was having this issue for a few days but fixed it by creating a new environment with older versions of the packages I needed, so ylnhari's suspicion that there might be some conflict with package versions seems to be on the money. Since I'm working through a class that wants us to have everything installed with Anaconda my environment isn't super custom, but it worked when I downgraded from the most up-to-date version to anaconda=5.3.0.

For a more general approach my intuition is to target the packages that are specifically referred to in gmaps's requirements.txt (six, ipython>=5.3.0, ipywidgets>=7.0.0, traitlets>=4.3.0, geojson>=2.0.0). I'm afraid I'm far too much of a novice to walk through building only what might be necessary into an environment, so I hope this is enough of a jumping off point for people who want to avoid installing bloat. However if anyone running into this issue wants a quick and dirty solution and isn't too picky about what gets added to the environment, here's what I did:

  1. Create new environment with python 3.7.0
  2. Activate the environment and install anaconda=5.3.0
  3. Install gmaps
  4. Since my environment's jupyter kernel wasn't created I used: python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
  5. ipywidgets widget extensions were enabled but despite using conda, gmaps's widget wasn't, so I ran: $ jupyter nbextension enable --py --sys-prefix gmaps to load it.

This is just a workaround I think if the current versions of one the gmaps requirements is causing conflicts. I went down a few rabbit holes looking into the errors that get logged to the console and came back with a potential issue with the JS compilier Babel's config. How, where and why that is now getting picked up with updates to python packages is not something I can even guess at let alone attempt to fix, but hopefully this workaround helps for people just looking for things to work!

@ylnhari
Copy link
Author

ylnhari commented Oct 14, 2022

@arooj1 , I tried running the same on my other workstation with Linux environment whose environment was untouched and it is working fine there ,now I strongly believe that this is due to some requirements libraries of g-maps that could be creating these issues try @sbenston solution let us know your experience.

@timcoote
Copy link

I fixed this in a development install by updating babel ( https://github.com/babel/babel-upgrade). The issue seems to be that webpack uses babel to transpile the JavaScript so that it works in older browsers. However, the default version, configured in js/.babelrc and described in js/package.json doesn't do this properly for ES6.

@philipperemy
Copy link

Thanks @timcoote .

After spending 7 hours on it, I finally found a way. I made a docker file that solves the problem:

FROM python:3.9.10-buster
MAINTAINER Philippe Remy <[email protected]>

EXPOSE 8888

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update

# Install specific version of node/npm
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs

# Install gmaps
RUN pip install pip --upgrade
RUN pip install jupyter
WORKDIR /gmaps
RUN apt-get install git && git clone https://github.com/pbugnion/gmaps.git .

WORKDIR /gmaps/js
RUN npx babel-upgrade --write
RUN npm update

WORKDIR /gmaps
RUN bash ./dev-install

ENTRYPOINT [ "jupyter-notebook", "--ip", "0.0.0.0", "--port", "8888", "--allow-root", "." ]

@tejalbarnwal
Copy link

tejalbarnwal commented May 17, 2023

did anybody find here solution to using python3.8 on a virtual environment without conda and without source installation

@philipperemy
Copy link

@tejalbarnwal it's not possible. You need to use the source installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants