Error using d3: "d3 is not defined"


I am starting to do my pininos with d3 in Python (using Jupyter ), with something very simple, but no matter what I do, I have errors. Go the code:

from IPython.core.display import HTML, Javascript
import json

#Llamo a d3 desde el directorio donde trabajo (bajé el zip y lo instalé en una carpeta)

HTML('''<script src="d3/d3.min.js"></script>''')

Now comes what is supposed to be done: a sign that says "Hello D3!" in orange letters

<style scoped>
.bedazzled {
  color: orange;
<div id="d3-div-1"></div>

var size_data = [10,20,30];"#d3-div-1").selectAll('.bedazzled')
      .style("font-size", function(d){ return "" + d + "px";})
      .text("Hello D3!");


The error I have is:

Javascript error adding output!
ReferenceError: d3 is not defined
See your browser Javascript console for more details.

I've tried incorporating <script src="d3/d3.min.js"></script> directly into the long code and into the first call to HTML (first block of code in this post), using <script src=""></script> and even <script src=""></script> with exactly the same result.

As you can imagine, I am somewhat frustrated with this matter, so any suggestion I will thank you infinitely.

asked by Alejandro Carrera 04.12.2018 в 01:45

1 answer


I found this answer in SO in English link

It seems that you have to import d3 globally using this code:

    paths: {
        d3: ""

require(["d3"], function(d3) {
    window.d3 = d3;

I tried it and it works for me

answered by 04.12.2018 / 02:37