jupyter-widgets / ipyleaflet

A Jupyter - Leaflet.js bridge
https://ipyleaflet.readthedocs.io
MIT License
1.48k stars 363 forks source link

Error displaying map in jupyter lab #336

Closed fitoprincipe closed 5 years ago

fitoprincipe commented 5 years ago

Hi,

ipyleaflet was working fine in Jupyter Lab until today.

I read https://github.com/jupyter-widgets/ipyleaflet/issues/202, so I checked node. I'm using version 8.11.1.

Just in case, I run jupyter labextension install jupyter-leaflet and jupyter labextension install @jupyter-widgets/jupyterlab-manager, but no luck.

ipyleaflet_recorte

It's working fine in a Jupyter Notebook

martinRenou commented 5 years ago

Hi @fitoprincipe, Just in case, are you sure you are running JupyterLab in the same environment? Could you try creating a core widget like an IntSlider? Does it work?

fitoprincipe commented 5 years ago

Hi @martinRenou, IntSlider and other widgets work fine. The only widget that doesn't is ipyleaflet. When I downgrade to the version I was using previously it works fine. How do I register it as a widget module (as the error says)?

(to understand my environment)

I am on Linux Mint. I run Jupyter Lab from terminal:

~$ jupyter lab

To install new kernels I use this guide. I have added some paths to PYTHONPATH by modifying the .profile file in my user folder.

Last week I added to it a local forked version of ipyleaflet to start "playing around" and see if I can contribute. Yesterday, when it stopped working, I removed that entry from PYTHONPATH and let the kernel use the vesion installed in the virtual enviroment, but isn't working. For working, I can downgrade, but as I'd like to contribute I need some help to get over this. Thank you =)

martinRenou commented 5 years ago

Can you try jupyter nbextension list? If it says that ipyleaflet is disabled you should try running

jupyter nbextension install --py --symlink --sys-prefix ipyleaflet
jupyter nbextension enable --py --sys-prefix ipyleaflet
fitoprincipe commented 5 years ago

This is the result of jupyter nbextension list:

Known nbextensions: config dir: /home/labgeo1/.jupyter/nbconfig notebook section jupyter-js-widgets/extension enabled

  • Validating: OK test enabled
  • Validating: problems found:
    • require? X test config dir: /home/labgeo1/Python/envs/geepy3/etc/jupyter/nbconfig notebook section jupyter-js-widgets/extension enabled
  • Validating: OK jupyter-leaflet/extension enabled
  • Validating: OK config dir: /usr/local/etc/jupyter/nbconfig notebook section bqplot/extension enabled
  • Validating: OK jupyter-leaflet/extension enabled
  • Validating: OK jupyter-vega/index enabled
  • Validating: OK jupyter-js-widgets/extension enabled
  • Validating: OK
martinRenou commented 5 years ago

That would be awesome if you could contribute! How did you install ipyleaflet? Did you follow the guide for installing ipyleaflet from sources?

fitoprincipe commented 5 years ago

Kind of.. I didn't use -e when pip install . and didn't execute the last two:

$ jupyter nbextension install --py --symlink --sys-prefix ipyleaflet $ jupyter nbextension enable --py --sys-prefix ipyleaflet

But first I'd like to solve the issue of not showing the map.. if I can't understand why it isn't working in a normal workflow, I won't feel confortable for contribution..

martinRenou commented 5 years ago

The thing is I think you have a broken installation. Maybe you installed ipyleaflet first using conda or pip, then you partially installed ipyleaflet from sources, and there might be a conflict between the two versions you installed. Removing ipyleaflet and installing it again from sources (following the guide) would be a good option.

martinRenou commented 5 years ago

Once installed from sources, you would need to run jupyter labextension install js from the root of the ipyleaflet directory in order to install the right JavaScript code for the lab extension

fitoprincipe commented 5 years ago

Ok, I'll try that and let you know. Is there something else to do for uninstalling beside pip uninstall?

And another question, can I have a virtual environment for the developing version (from source) and another for the stable version? since I use it in my every day job

martinRenou commented 5 years ago

My guess is that you first installed an earlier ipyleaflet version than 0.10.1 using pip (e.g. 0.9.0). Then tried to install from sources using master, which is 0.10.1. But you partially installed from sources, you only installed the Python code, and it does not find the JavaScript code for 0.10.1. That could be why it complains.

Is there something else to do for uninstalling beside pip uninstall?

That should do the trick if you only installed using pip

can I have a virtual environment for the developing version (from source) and another for the stable version?

I think so. I don't know what you are using for creating a virtual environment, but creating a separate virtual env with Jupyter and ipyleaflet in it for development sounds like a good idea :)

fitoprincipe commented 5 years ago

In the last part is where I get a little confuse.. I use virtualenv to create virtual environments for python, but as far as I know it does not isolate binaries like Jupyter.. how could I make a virtual environment with a different Jupyter (without using Docker)?

For example, when running

$ jupyter nbextension install --py --symlink --sys-prefix ipyleaflet $ jupyter nbextension enable --py --sys-prefix ipyleaflet

does the same if the environment is activated or not... does it?

martinRenou commented 5 years ago

as far as I know it does not isolate binaries like Jupyter

That's not what I would expect... What does it say if you do which jupyter? I think it depends if you installed jupyter globally or not.

If you installed jupyter globally (not when the environment is activated) then I guess which jupyter will say the same thing in and out of the environment.

If you installed jupyter in the environment and globally, then which jupyter should say different things in and out of the environment.

If you only installed jupyter in the environment, I expect jupyter to fail with a Command jupyter not found when out of the environment.

EDIT: For example if I run which jupyter from my ipyleaflet conda environment it says /home/martin/miniconda3/envs/ipyleaflet/bin/jupyter. If I run it globally it says nothing because jupyter is not installed globally.

fitoprincipe commented 5 years ago

You are right, it DOES isolate Jupyer.. great! when environment is activated:

(geepy3) $ which jupyter (geepy3) $ /home/labgeo1/Python/envs/geepy3/bin/jupyter

when not environment is activated:

$ which jupyer $ /usr/local/bin/jupyter

But I always run it from the global scope, and install kernels for each environment using the guide I told you before.. maybe I just should run the jupyter installed in each environment.. I'll try that!

Thank you @martinRenou! you've been really helpful =)

martinRenou commented 5 years ago

Oh yeah, that could be your issue :) Happy I could help! I think it is best practice to have the minimum installed in the global environment, and only have isolated environments for each project/task you have. This way you do not depend on packages from a different environment and you don't have version collisions like the one you have.

fitoprincipe commented 5 years ago

Ok, I have done some steps.. created a clean virtual environment using virtualenv and installed ipyleaflet from source as you suggested, and checked which jupyter to ensure it's running from the correct environment.. but I think the local installation of it is messing it up..

(env) $ jupyter lab [I 10:29:25.730 LabApp] JupyterLab extension loaded from /usr/local/lib/python2.7/dist-packages/jupyterlab [I 10:29:25.730 LabApp] JupyterLab application directory is /usr/local/share/jupyter/lab [W 10:29:25.751 LabApp] JupyterLab server extension not enabled, manually loading... [I 10:29:25.752 LabApp] JupyterLab extension loaded from /usr/local/lib/python2.7/dist-packages/jupyterlab

should I uninstall jupyter from the local scope?

martinRenou commented 5 years ago

Yeah I think it would be cleaner. Then you would have to run pip install jupyter from your environment and other environments that needs it

fitoprincipe commented 5 years ago

Ok I'll try that! Thank you =)

fitoprincipe commented 5 years ago

I made all steps I can think off.. but no luck with Jupyter Lab.. it works fine in Jupyter Notebook..

$ jupyter nbextension list

Known nbextensions:
  config dir: /home/labgeo1/.jupyter/nbconfig
    notebook section
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
  config dir: /home/labgeo1/Python/envs/ipyleaflet/etc/jupyter/nbconfig
    notebook section
      jupyter-leaflet/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK

When Jupyter Lab starts:

[I 12:12:23.709 LabApp] The port 8888 is already in use, trying another port.
[I 12:12:23.722 LabApp] JupyterLab extension loaded from /home/labgeo1/Python/envs/ipyleaflet/lib/python3.5/site-packages/jupyterlab
[I 12:12:23.722 LabApp] JupyterLab application directory is /home/labgeo1/Python/envs/ipyleaflet/share/jupyter/lab
[W 12:12:23.724 LabApp] JupyterLab server extension not enabled, manually loading...
[I 12:12:23.729 LabApp] JupyterLab extension loaded from /home/labgeo1/Python/envs/ipyleaflet/lib/python3.5/site-packages/jupyterlab
[I 12:12:23.729 LabApp] JupyterLab application directory is /home/labgeo1/Python/envs/ipyleaflet/share/jupyter/lab
[I 12:12:23.730 LabApp] Serving notebooks from local directory: /home/labgeo1/Python/notebooks
[I 12:12:23.730 LabApp] The Jupyter Notebook is running at:
[I 12:12:23.730 LabApp] http://localhost:8889/?token=becdba02e97e5fdff3467beb07193398e28974a992a7d266
[I 12:12:23.730 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 12:12:23.733 LabApp] 

    To access the notebook, open this file in a browser:
        file:///run/user/1000/jupyter/nbserver-28016-open.html
    Or copy and paste one of these URLs:
        http://localhost:8889/?token=becdba02e97e5fdff3467beb07193398e28974a992a7d266
Se creó una nueva ventana en la sesión existente del navegador.
[I 12:12:26.050 LabApp] Node v8.11.1

[I 12:12:26.137 LabApp] Build is up to date
[I 12:12:26.753 LabApp] Kernel started: 69cc6408-89b1-4631-9868-1545903d76fd
[I 12:12:28.478 LabApp] Adapting to protocol v5.1 for kernel 69cc6408-89b1-4631-9868-1545903d76fd
[I 12:12:28.498 LabApp] Adapting to protocol v5.1 for kernel 69cc6408-89b1-4631-9868-1545903d76fd
[I 12:13:05.315 LabApp] Starting buffering for 69cc6408-89b1-4631-9868-1545903d76fd:3d83db55-5cfb-4000-a2c9-84c3678bdf74

all paths are within the virtual environment now.. but the error is exactly the same as the first issue post

martinRenou commented 5 years ago

Ok, do you have core widgets working?

fitoprincipe commented 5 years ago

yes, I forgot to mention.. IntSlider is working fine

martinRenou commented 5 years ago

Did you run jupyter labextension install js after following the installation from sources instructions?

fitoprincipe commented 5 years ago

Nope, I didn't see that command.. I ran it now but fails..

output (with --debug):

Traceback (most recent call last):

  File "/home/labgeo1/Python/envs/ipyleaflet/lib/python3.5/site-packages/jupyterlab/labextensions.py", line 77, in start
    ans = self.run_task()

  File "/home/labgeo1/Python/envs/ipyleaflet/lib/python3.5/site-packages/jupyterlab/labextensions.py", line 106, in run_task
    for arg in self.extra_args

  File "/home/labgeo1/Python/envs/ipyleaflet/lib/python3.5/site-packages/jupyterlab/labextensions.py", line 106, in <listcomp>
    for arg in self.extra_args

  File "/home/labgeo1/Python/envs/ipyleaflet/lib/python3.5/site-packages/jupyterlab/commands.py", line 219, in install_extension
    return handler.install_extension(extension)

  File "/home/labgeo1/Python/envs/ipyleaflet/lib/python3.5/site-packages/jupyterlab/commands.py", line 418, in install_extension
    info = self._install_extension(extension, tempdir)

  File "/home/labgeo1/Python/envs/ipyleaflet/lib/python3.5/site-packages/jupyterlab/commands.py", line 1257, in _install_extension
    raise ValueError(msg % (extension, '\n'.join(messages)))

ValueError: "js" is not a valid extension:
No `jupyterlab` key

Errored, use --debug for full output:
ValueError: "js" is not a valid extension:
No `jupyterlab` key
martinRenou commented 5 years ago

Nope, I didn't see that command

Yes we need to improve the documentation.. Also you need nodejs installed for this command to work.

I'm unsure what this error message means... Maybe you did not run it from the ipyleaflet root directory? In the command js points to the js subdirectory in the ipyleaflet repo.

fitoprincipe commented 5 years ago

That is it! It's working now, thank you!!

My final question before closing the issue, how do you handle development process?? when you make a change, what you do? reinstall everything?? This is why I put development packages in my pythonpath.. so if I make a change, I just rerun the kernel and that's it, I can quickly test the change..

martinRenou commented 5 years ago

That is it! It's working now, thank you!!

Awesome!

how do you handle development process??

Well, it depends.

If you are working on the Python code and you installed it using -e, you only need to restart the kernel and you would see your changes.

If you are working on the JavaScript code:

This should be part of the documentation as well...

martinRenou commented 5 years ago

I personally prefer developing on the classical Notebook, it is a lot faster. And you can check that your changes work on JupyterLab as well once you are done developing (and it should work).

fitoprincipe commented 5 years ago

Very valuable information! Once again, thank you @martinRenou! Closing now =)

martinRenou commented 5 years ago

Sure! :)

Lynnn96 commented 4 years ago

Try to reopen Jupyter notebook, the the map will display